web.xml关键元素分析
- welcome-file-list 和 welcome-file元素
<welcome-file-list>
<!--欢迎页面-->
<welcome-file>a.jsp</welcome-file>
<welcome-file>b.jsp</welcome-file>
</welcome-file-list>
在上述代码中,Tomcat会按顺序来查找欢迎页面,如果存在a.jsp,则他就是欢迎面,否则继续查找b.jsp
- filter和file-mapping元素
<filter>
<!--指定filter的名字,不能为空-->
<filter-name>struts2</filter-name>
<!--指定filter的实现类,此处使用的是struts2提供的过滤器类-->
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
----------------------------------------------------------------------------------------------------------------------------
<!--定义filter所拦截的URL地址-->
<filter-mapping>
<!--filter的名字,必须是filter元素中申明过的过滤器的名字-->
<filter-name>struts2</filter-name>
<!--filter负责拦截的URL路径-->
<url-pattern>/*</url-pattern>
</filter-mapping>
- error-page元素
<error-page>
<!--指定错误代码-->
<error-code>404<error-code>
<!--发生错误返回指定的文件-->
<location>/error.jsp</location>
</error-page>
<!--下面的代码和上面效果一样-->
<!--配置error-page用于捕获异常-->
<error-page>
<exception-type> java.long.Exception </exception-type> <!--指定异常类-->
<location>/error.jsp</location>
</error-page>
- listener元素
<listerner>
<listener-class>org.springframework.web.context.ContextLoaderListerner
</listener-class>
</listener>
- session-config元素
<!--会话时间配置-->
<session-config>
<session-timeout>30</session-timeout>
</session-config>
- init-param元素
<!--配置常量-->
<init-param>
<param-name>struts.i18n.encoding </param-name>
<param-value>UTF-8</param-value>
</init-param>