六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 310|回复: 0

天乙论坛v8 web.xml 分析

[复制链接]

升级  56.67%

39

主题

39

主题

39

主题

秀才

Rank: 2

积分
135
 楼主| 发表于 2013-2-6 11:06:32 | 显示全部楼层 |阅读模式
<div class="highlighter">

  • <?xmlversion="1.0"encoding="UTF-8"?>
  • <!--
  • http://www.ibm.com/developerworks/cn/java/j-tomcat/
  • 应该指定它们为web.xml文件内<web-app>标记的子标记。
  • -->
  • <web-appversion="2.4"
  • xmlns="http://java.sun.com/xml/ns/j2ee"
  • xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  • xsi:schemaLocation="http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  • <display-name>bbscs8</display-name>
  • <filter>
  • <filter-name>UrlRewriteFilter</filter-name>
  • <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
  • </filter>
  • <!--
  • <filter-mapping>标记代表了一个过滤器的映射,
  • 指定了过滤器会对其产生作用的URL的子集。
  • 它必须有一个<filter-name>子元素与能找到
  • 您希望映射的过滤器的过滤器定义相对应。
  • -->
  • <filter-mapping>
  • <filter-name>UrlRewriteFilter</filter-name>
  • <url-pattern>/*</url-pattern>
  • </filter-mapping>
  • <!--
  • <filter>
  • <filter-name>SidFilter</filter-name>
  • <filter-class>com.laoer.bbscs.web.servlet.SidFilter</filter-class>
  • </filter>
  • <filter-mapping>
  • <filter-name>SidFilter</filter-name>
  • <url-pattern>/*</url-pattern>
  • </filter-mapping>
  • -->
  • <filter>
  • <filter-name>CharacterEncodingFilter</filter-name>
  • <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  • <!--
  • init-param>子元素为过滤器实例提供初始化参数
  • -->
  • <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>
  • <!--
  • 如果应用中使用了OpenSessionInViewFilter或者OpenSessionInViewInterceptor,
  • 所有打开的session会被保存在一个线程变量里。在线程退出前通过
  • OpenSessionInViewFilter或者OpenSessionInViewInterceptor断开这些session。
  • 为什么这么做?这主要是为了实现Hibernate的延迟加载功能。基于一个请求
  • 一个hibernatesession的原则。
  • -->
  • <filter>
  • <filter-name>OpenSessionInViewFilter</filter-name>
  • <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
  • </filter>
  • <filter-mapping>
  • <filter-name>OpenSessionInViewFilter</filter-name>
  • <url-pattern>/*</url-pattern>
  • </filter-mapping>
  • <!--
  • 在做上传文件的时候,
  • 要在web.xml中增加ActionContextCleanUp这个filter,
  • 如果不增加,会发生第一次上传取不到文件的情况
  • -->
  • <filter>
  • <filter-name>struts-cleanup</filter-name>
  • <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
  • </filter>
  • <filter-mapping>
  • <filter-name>struts-cleanup</filter-name>
  • <url-pattern>/*</url-pattern>
  • </filter-mapping>
  • <!--
  • 核心控制器:FilterDispatcher。
  • FilterDispatcher类存在于org.apache.struts2.dispatcher包下,
  • 它继承了javax.servlet.Filter接口。在应用的web.xml文件中需要配置该控制器,
  • 用来接收用户所有请求,FilterDispatcher会判断请求是否为*.action模式,
  • 如果匹配,则FilterDispatcher将请求转发给Struts2.0框架进行处理。
  • 在web.xml文件中对FilterDispatcher的配置

  • -->
  • <filter>
  • <filter-name>Struts2</filter-name>
  • <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  • </filter>
  • <filter-mapping>
  • <filter-name>Struts2</filter-name>
  • <url-pattern>/*</url-pattern>
  • <dispatcher>REQUEST</dispatcher>
  • <dispatcher>FORWARD</dispatcher>
  • </filter-mapping>
  • <context-param>
  • <param-name>urlrewrite</param-name>
  • <param-value>false</param-value>
  • </context-param>
  • <context-param>
  • <param-name>cluster</param-name>
  • <param-value>false</param-value>
  • </context-param>
  • <context-param>
  • <param-name>servletmapping</param-name>
  • <param-value>*.bbscs</param-value>
  • </context-param>
  • <context-param>
  • <param-name>poststoragemode</param-name>
  • <param-value>1</param-value>
  • </context-param>
  • <listener>
  • <listener-class>com.laoer.bbscs.web.servlet.SysListener</listener-class>
  • </listener>
  • <context-param>
  • <!--contextConfigLocation参数定义了要装入的Spring配置文件。-->
  • <param-name>contextConfigLocation</param-name>
  • <param-value>/WEB-INF/applicationContext.xml,/WEB-INF/action-servlet.xml</param-value>
  • </context-param>
  • <!--
  • 有两种方法,一个是用ContextLoaderListener这个Listerner,
  • 另一个是ContextLoaderServlet这个Servlet,
  • 这两个方法都是在web应用启动的时候来初始化WebApplicationContext,
  • 我个人认为Listerner要比Servlet更好一些,
  • 因为Listerner监听应用的启动和结束,而Servlet得启动要稍微延迟一些,
  • 如果在这时要做一些业务的操作,启动的前后顺序是有影响的。

  • ContextLoader是一个工具类,用来初始化WebApplicationContext,
  • 其主要方法就是initWebApplicationContext,
  • 我们继续追踪initWebApplicationContext这个方法
  • (具体代码我不贴出,大家可以看Spring中的源码),
  • 我们发现,原来ContextLoader是把WebApplicationContext
  • (XmlWebApplicationContext是默认实现类)放在了ServletContext中,
  • ServletContext也是一个“容器”,
  • 也是一个类似Map的结构,
  • 而WebApplicationContext在ServletContext中的
  • KEY就是WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
  • 我们如果要使用WebApplicationContext则需要从ServletContext取出,
  • Spring提供了一个WebApplicationContextUtils类,
  • 可以方便的取出WebApplicationContext,只要把ServletContext传入就可以了。
  • -->
  • <listener>
  • <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  • </listener>
  • <servlet>
  • <servlet-name>authimg</servlet-name>
  • <servlet-class>com.laoer.bbscs.web.servlet.AuthImg</servlet-class>
  • </servlet>
  • <servlet-mapping>
  • <servlet-name>authimg</servlet-name>
  • <url-pattern>/authimg</url-pattern>
  • </servlet-mapping>
  • <servlet>
  • <servlet-name>rss</servlet-name>
  • <servlet-class>com.laoer.bbscs.web.servlet.Rss</servlet-class>
  • </servlet>
  • <servlet-mapping>
  • <servlet-name>rss</servlet-name>
  • <url-pattern>/rss</url-pattern>
  • </servlet-mapping>
  • <welcome-file-list>
  • <welcome-file>index.jsp</welcome-file>
  • </welcome-file-list>
  • <!--
  • 在Tomcat5.0.x中,Tomcat支持了JSP2.0的规格,
  • 同时也支持了部分J2EE1.4的规格,
  • 在J2EE1.4的规格中,
  • 有关JSP的部份,有一个<jsp-config>的XMLTag,
  • 这个XML区块用来定义与JSP相关的特殊属性,
  • 包含采用的taglib与以下说明的<jsp-property-group>,
  • 而解决include档中文问题的方法就定义在<jsp-roperty-group>中
  • -->
  • <jsp-config>
  • <taglib>
  • <taglib-uri>/WEB-INF/struts-tags.tld</taglib-uri>
  • <taglib-location>/WEB-INF/struts-tags.tld</taglib-location>
  • </taglib>
  • </jsp-config>
  • <error-page>
  • <error-code>401</error-code>
  • <location>/401.htm</location>
  • </error-page>
  • <error-page>
  • <error-code>403</error-code>
  • <location>/403.htm</location>
  • </error-page>
  • <error-page>
  • <error-code>404</error-code>
  • <location>/404.htm</location>
  • </error-page>
  • <error-page>
  • <error-code>500</error-code>
  • <location>/500.htm</location>
  • </error-page>
  • <error-page>
  • <exception-type>java.lang.NullPointerException</exception-type>
  • <location>/npe.htm</location>
  • </error-page>
  • </web-app>

您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表