【发布时间】:2016-08-14 23:08:36
【问题描述】:
我正在 tomcat apache 服务器上使用 java spring 和 jsp 编写一个名为“webdemo”的简单 Web 应用程序。我的目标是将资产(jsp,图像,css,js)与项目war文件分开并将它们存储在tomcat的类路径中,我将其设置为tomact的“common”文件夹。
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>
我们在 tomcat 上托管了近 300 个 web 项目,最终目标是将所有资产分别放在 tomcat 的公共文件夹下的每个 web 项目的单个位置。
我们将不胜感激。
【问题讨论】:
标签: java spring jsp tomcat servlets