常用java的war项目的web.xml配置

3 篇文章 0 订阅

常用java的war项目的web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	version="2.5">
	<display-name>junli_web</display-name>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
	 <!-- 初始化spring容器 -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:spring/spring*.xml</param-value>
<!-- 		<param-value>classpath:spring*.xml;classpath:spring-mybatis.xml</param-value> -->
		<!-- <param-value>classpath:spring-*.xml</param-value> -->
	</context-param>
	<!--增加对静态资源的处理,当前的设置必须在Spring的Dispatcher的前面 -->
	<servlet-mapping>
		<servlet-name>default</servlet-name>
		<url-pattern>/static/*</url-pattern>
	</servlet-mapping>

	<!-- 解决post乱码 -->
	<filter>
		<description>字符集过滤器</description>
		<filter-name>CharacterEncodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<description>字符集编码</description>
			<param-name>encoding</param-name>
			<param-value>utf-8</param-value>
		</init-param>
		<init-param>
			<param-name>forceRequestEncoding</param-name>
			<param-value>false</param-value>
		</init-param>
		<init-param>
			<param-name>forceResponseEncoding</param-name>
			<param-value>true</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>CharacterEncodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<!-- spring监听器 -->
	<listener>
		<description>spring监听器</description>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<listener>
		<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
	</listener>
<!-- springmvc的前端控制器 -->
<servlet>
	<description>spring mvc servlet</description>
	<servlet-name>springMvc</servlet-name>
	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
	<!-- contextConfigLocation不是必须的, 如果不配置contextConfigLocation, springmvc的配置文件默认在:WEB-INF/servlet的name+"-servlet.xml" -->
	<init-param>
		<description>spring mvc 配置文件</description>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:spring/spring-mvc.xml</param-value>
	</init-param>
	<load-on-startup>1</load-on-startup>
</servlet>
<!-- URL 拦截形式 -->
<servlet-mapping>
	<servlet-name>springMvc</servlet-name>
	<!-- /* 表示拦截所有,包括转发的Jsp页面 这是错误的,不能用 -->
	<!-- / 表示拦截所有的静态资源,不包括转发JSP -->
	<url-pattern>/</url-pattern>
	<!-- 伪静态化:SEO 搜索引擎优化 -->
	<!-- SEO:搜索引擎优化,为了提高网站的流量, 提高在各搜索引擎中的搜索排名,需要进行优化, 那么可以为动态网站伪静态化,以提高排名。 -->
	<!-- <url-pattern>*.html</url-pattern> -->
</servlet-mapping>
<!-- 设置session超时时间,单位分钟 -->
<session-config>
	<session-timeout>30</session-timeout>
</session-config>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值