j2ee web.xml 整理

web.xml中有各种各样的标签,了解一下具体标签的具体用途. 
1,站点的名称和说明. 
2,针对环境参数初始化 
3,Servlet的名称和映射 
4,Session生命周期的设定 
5,Tag library的对映 
6,Jsp的设定 
7,Mime Type处理 
8,错误处理 
9,利用JDNI取得站台资源...等等; 

<web-app version="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/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

这里介绍了这个xml的版本,xml概括的来源xsi:schema... 

<display-name>Develop</display-name>
<description>JSP 2.0 Tech Book's Examples</description>
<icon>
   <small-icon>/images/small.gif</small-icon>
   <large-icon>/images/large.gir</large-icon>
</icon>

<display-name>站点名称,<description>站点描述,<icon>站点小\中图标的路径.<small-icon>元素应指向web站台中某个小图标的路径,大小为16 X 16 pixel,但是图象文件必须为GIF或JPEG格式,<large-icon>元素应指向web站台中某个大图表路径,大小为32 X 32 pixel,但是图象文件必须为GIF或JPEG的格式. 
<distributable/>站台是否可分布式处理,集群web容器. 

<context-param>
   <param-name>param_name</param-name>
   <param-value>param_value</param-value>
</context-param>

这个标签键值对形式,为JSP/Servlet提供参数,此所设定的参数,在JSP网页中可以使用下列方法来取得:${initParam.param_name},若在Servlet可以使用下列方法来获得: 
String param_name=getServletContext().getInitParamter("param_name"); 

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:/applicationContext-resources.xml
            classpath:/applicationContext-dao.xml
            classpath:/applicationContext-service.xml
            classpath*:/applicationContext.xml
            /WEB-INF/applicationContext*.xml
            /WEB-INF/cxf-servlet.xml
            /WEB-INF/security.xml
        </param-value>
    </context-param>

  

(以上这种配法没问题,用到了一个通配符,这里表示跟src下包是同级的xml,当使用maven时有2个main/resources,test/resources,这个文件夹则表示src下的

<filter>
    <filter-name>encodingFilter</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-name过滤器名称,filter-class类的完全限定名,以及2个参数!可以按自己具体需要来定义! 

<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST|INCLUDE|FORWARD|ERROR</disaptcher>
    <dispatcher>REQUEST|INCLUDE|FORWARD|ERROR</disaptcher>
</filter-mapping>

映射过滤器,注意name要相同,这里有个dispatcher标签,他有4个选择,默认为REQUEST!可以配置多个. 

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

这个就是加载spring上下文,也就是说在启动spring之前需要加载的 

<session-config>
   <session-timeout>20</session-timeout>
</session-config>

Session生命周期,分! 

<error-page>
   <error-code>404</error-code>
   <location>/error404.jsp</location>
</error-page>
<error-page>
   <exception-type>java.lang.Exception</exception-type>
   <location>/except.jsp</location>
</error-page>

这些是配置需要的一些页面,在需要时!可直接跳404 
<el-ignored>true|false</el-ignored> 
若为true,表示不支持EL语法. 

<scripting-invalid>true|false</scripting-invalid> 
若为true表示不支持<%scription%>语法. 

<page-encoding>encoding</page-encoding> 
设定JSP网页的编码 

<include-prelude>.jspf</include-prelude> 
设置JSP网页的抬头,扩展名为.jspf 

<include-coda>.jspf</include-coda> 
设置JSP网页的结尾,扩展名为.jspf 

posted @ 2013-10-25 16:10  暖流  阅读(286)  评论(0编辑  收藏  举报