Spring项目开发笔记系列(二)

时间:2021-12-13 08:53:08

Spring项目开发笔记系列(二)

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee  
                      http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <!--webAppRootKey 属性为crbt.root 代表webApp的根目录,这样就能在properties文件中定义-->
  <context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>crbt.root</param-value>
  </context-param>
  <!-- contextConfigLocation 属性代表spring-config.xml文件的地址-->
  <context-param>
    <description>Spring2.0 Config</description>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/config/spring-config.xml</param-value>
  </context-param>
  <!-- log4jConfigLocation 属性代表log4j.properties文件的地址-->
  <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/config/log4j.properties</param-value>
  </context-param>
  <!-- 加上这个Spring的Log4j侦听类,注意在JBOSS里面,不需要这个类,注释掉,不然会冲突 -->
  <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener>
  <!-- 加上这个Spring的侦听类 -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <!-- 设置字符编码集,默认是utf-8,true,两个参数都可以省略,ignore=true/yes/y表示使用设定的编码 -->
  <filter>
    <filter-name>EncodingFilter</filter-name>
    <filter-class>com.daniel.lr.crbt.service.web.filter.EncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>utf-8</param-value>
    </init-param>
    <init-param>
      <param-name>ignore</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>EncodingFilter</filter-name>
    <url-pattern>*.do</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>EncodingFilter</filter-name>
    <url-pattern>*.jsp</url-pattern>
  </filter-mapping>
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/config/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>2</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>2</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

 这是项目的web.xml配置文件,添加了几项主要用于加载spring,log4j,过滤字符编码等~