我正在使用java和jsp在tomcat服务器上编写一个名为"webdemo“的简单web应用程序。我的目标是将资产(jsp、图像、css、js)从projects文件中分离出来,并将它们存储在tomcat的类路径中,我将其设置为tomact的“公共”文件夹。
webdemo-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<import resource="externalizationContext.xml"/>
<mvc:annotation-driven/>
<context:component-scan base-package="com.mckesson.voucher"/>
<mvc:resources mapping="/images/**" location="classpath:application-assets/webdemo/images/" />
<mvc:resources mapping="/scripts/**" location="classpath:application-assets/webdemo/scripts/" />
<bean id="couponBean" class="com.mckesson.voucher.model.CouponBean" scope="session">
<aop:scoped-proxy />
</bean>
<util:properties id="voucherProperties"
location="classpath:application-config/webdemo/externalization/webdemo.properties" />
<util:properties id="voucherEnvProperties"
location="classpath:application-config/webdemo/logging/loggingTags.properties" />
<util:properties id="voucherDBEnvProperties"
location="classpath:application-config/datasource/dataSource.properties" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="classpath:application-assets/webdemo/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>web.xml
<!-- General description of your web application -->
<display-name>McKesson webdemo</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dbContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>webdemo</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>webdemo</servlet-name>
<url-pattern>/home.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>webdemo</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>home.html</welcome-file>
</welcome-file-list>
<!-- Define the default session timeout for your application,
in minutes. From a servlet or JSP page, you can modify
the timeout for a particular session dynamically by using
HttpSession.getMaxInactiveInterval(). -->
<session-config>
<session-timeout>30</session-timeout><!-- 30 minutes -->
</session-config>
</web-app>我们有近300个托管在tomcat上的网络项目,最终目标是将所有的资产放在一个单独的地方,分别放在tomcat的公用文件夹下的每个web项目中。
这里的任何帮助都将不胜感激。
发布于 2016-08-15 02:49:07
这其实是个好主意,但你搞错了。您需要了解的一件事是,您不想分离jsp。春天留着吧。您希望将js、css和图像分开,因为它们是静态内容。在企业环境中这样做的常见方法是在Tomcat服务器前面有一个way服务器,比如Apache。您将静态内容放在Apache服务器上,并配置该服务器将静态内容传递给浏览器,而对动态内容的调用则被发送到Tomcat并通过Apache服务器转发。这减少了Tomcat服务器上的负载。您可能可以在一台服务器上完成这一切,但我还没有尝试过。
https://stackoverflow.com/questions/38947414
复制相似问题