zoukankan      html  css  js  c++  java
  • web.xml详解

    1.<context-param>
    context-param 元素用来设定web站台的环境参数(context),它包含两个子元素:
    param-name和param-value.
    <param-name>参数名称</param-name>
    设定Context名称
    <param-value>值</param-value>
    设定Context名称的值
    </context-param>
    范例:
    <context-param>
       <param-name>param_name</param-name>
       <param-value>param_value</param-value>
    </context-param>
    此所设定的参数,在JSP网页中可以使用下列方法来取得:
    ${initParam.param_name}
    若在Servlet可以使用下列方法来获得:
    String param_name=getServletContext().getInitParamter("param_name");

    2.<filter>
    filter元素用来声明filter的相关设定<filter-name>Filter的名称</filter-name>
    定义Filter的名称.
    <filter-class>Filter的类名称</filter-class>
    定义Filter的类名称.例如:com.foo.hello
    </filter>
    范例:
    <filter>
    <filter-name>setCharacterEncoding</filter-name>
    <filter-class>coreservlet.javaworld.CH11.SetCharacterEncodingFilter</filter-class>
    <init-param>
         <param-name>encoding</param-name>
         <param-value>GB2312</param-value>
    </init-param>

    </filter>

    3.<filter-mapping>
    filter-mapping 元素的两个主要子元素filter-name和url-pattern.用来定义Filter所对应的URL.
    <filter-name>Filter的名称</filter-name>
    定义Filter的名称.
    <url-pattern>URL</url-pattern>
    Filter所对应的RUL.例如:<url-pattern>/Filter/Hello</url-pattern>

    </filter-mapping>
    范例:
    <filter-mapping>
       <filter-name>GZIPEncoding</filter-name>
       <url-pattern>/*</url-pattern>
    </filter-mapping>
    4.<listener>
    listener元素用来定义Listener接口,它的主要子元素为<listener-class>
    <listen-class>Listener的类名称</listener-class>
    定义Listener的类名称.例如: com.foo.hello
    <listener>
    范例:
    <listener>
    <listener-class>coreservlet.javaworld.CH11.ContenxtListener</listener-class>
    </listener>
    5.<servlet-mapping>
    servlet-mapping元素包含两个子元素servlet-name和url-pattern.用来定义servlet所对应URL.
    <servlet-name>Servlet的名称</servlet-name>
    定义Servlet的名称.
    <url-pattern>Servlet URL</url-pattern>
    定义Servlet所对应的RUL.例如:<url-pattern>/Servlet/Hello</url-pattern>
    </servlet-mapping>
    范例:
    <servlet-mapping>
       <servlet-name>LoginChecker</servlet-name>
       <url-pattern>/LoginChecker</url-pattern>
    </servlet-mapping>

    6.<welcome-file-list>
    welcome-file-list包含一个子元素welcome-file.用来定义首页列单.
    <welcome-file>用来指定首页文件名称</welcome-flie>
    welcome-file用来指定首页文件名称.我们可以用<welcome-file>指定几个首页,而服务器会依照设定的顺序来找首页.
    范例:
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.htm</welcome-file>
    </welcome-file-list>
    7.<error-page>
    error-page元素包含三个子元素error-code,exception-type和location.将错误代码(Error Code)或异常(Exception)的种类对应
    到web站台资源路径.
    <error-code>错误代码</error-code>
    HTTP Error code,例如: 404
    <exception-type>Exception</exception-type>
    一个完整名称的Java异常类型
    <location>/路径</location>
    在web站台内的相关资源路径
    </error-page>
    范例:
    <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>

    8.<taglib>
    taglib元素包含两个子元素taglib-uri和taglib-location.用来设定JSP网页用到的Tag Library路径.
    <taglib-uri>URI</taglib-uri>
       taglib-uri定义TLD文件的URI,JSP网页的taglib指令可以经由这个URI存取到TLD文件.
    <taglib-location>/WEB-INF/lib/xxx.tld</taglib-laction>
       TLD文件对应Web站台的存放位置.
    </taglib>

  • 相关阅读:
    POJ3683 Priest John's Busiest Day
    POJ3678 Katu Puzzle
    洛谷4782 【模板】2-SAT 问题
    BZOJ2330或洛谷3275 [SCOI2011]糖果
    POJ1236或洛谷2746或洛谷2812 Network of Schools
    POJ2230 Watchcow
    POJ2942 Knights of the Round Table
    POJ3694 Network
    BZOJ1123或洛谷3469 [POI2008]BLO-Blockade
    animition动画的加入
  • 原文地址:https://www.cnblogs.com/hy928302776/p/3193398.html
Copyright © 2011-2022 走看看