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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 id="WebApp_ID" version="2.5">
 <!-- ****************************************配置项目名**************************************** -->
 <display-name>crm</display-name>

 <!-- 容器对于web.xml的加载顺序是context-param、listener、filter、servlet -->
 <!--filter是过滤器 filter-name 名字 filter-class 类 建立自定义过滤器需要实现javax.servlet.Filter接口,并实现其中init、doFilter、destroy三个方法
  filter-mapping 配置所拦截的请求 -->
 <!--****************************Spring的字符集过滤器用于处理项目中的乱码问题***************************** -->
 <filter>
  <filter-name>characterEncodingFilter</filter-name>
  <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  <init-param>
   <param-name>encoding</param-name>
   <param-value>UTF-8</param-value>
  </init-param>
  <init-param>
   <param-name>forceEncoding</param-name>
   <param-value>true</param-value>
  </init-param>
 </filter>
 <filter-mapping>
  <filter-name>characterEncodingFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 
 <!-- *********************************配置Struts2的核心Filter********************************* -->
 <filter>
  <filter-name>struts</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
 </filter>
 <!-- 配置Struts2拦截的请求 /* 表示所有请求 -->
 <filter-mapping>
  <filter-name>struts</filter-name>
  <url-pattern>*.action</url-pattern>
  <url-pattern>*.jsp</url-pattern>
  <url-pattern>*.do</url-pattern>
 </filter-mapping>

 <!-- ***********************************配置context-param*********************************** -->
 <!--context-param该元素用来声明应用范围(整个WEB项目)内的上下文初始化参数 param-name 设定上下文的参数名称。必须是唯一名称
  param-value 设定的参数名称的值 加载Spring配置文件 ,多个文件之间用逗号隔开,如:/WEB-INF/classes/springContext.xml,
  /WEB-INF/classes/springconfig/*.xml -->
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
        /WEB-INF/classes/springContext.xml
        </param-value>
 </context-param>

 <!-- ****************************************配置监听**************************************** -->
 <!-- 创建监听(备注:listener定义的类可以是自定义的类但必须需要继承ServletContextListener) -->
 <!-- 加载两个Spring的监听 -->
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 <listener>
  <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
 </listener>
 <!-- *******************自定义监听类******************* -->
 <!-- 自定义监听类,加载系统配置文件 -->
 <!-- <listener> <listener-class>com.jia.init.MyListener</listener-class>
  </listener> -->

 <!-- *************************************配置错误跳转页面************************************** -->
 <error-page>
  <error-code>500</error-code>
  <location>/jsp/error.jsp</location>
 </error-page>
 <error-page>
  <error-code>404</error-code>
  <location>/jsp/error.jsp</location>
 </error-page>
 <error-page>
  <exception-type>java.lang.Exception</exception-type>
  <location>/jsp/error.jsp</location>
 </error-page>

 <!-- ***********************************配置Web应用的首页列表************************************ -->
 <welcome-file-list>
  <welcome-file>jsp/login.jsp</welcome-file>
  <welcome-file>jsp/login.html</welcome-file>
 </welcome-file-list>
</web-app>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值