web.xml文件的简单说明

在javaEE提供的tutorial中的hello1中的web.xml文件写到:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app version="3.1" 
 3          xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
 4          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 5          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
 6     <context-param>
 7         <param-name>javax.faces.PROJECT_STAGE</param-name>
 8         <param-value>Development</param-value>
 9     </context-param>
10     <servlet>
11         <servlet-name>Faces Servlet</servlet-name>
12         <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
13         <load-on-startup>1</load-on-startup>
14     </servlet>
15     <servlet-mapping>
16         <servlet-name>Faces Servlet</servlet-name>
17         <url-pattern>*.xhtml</url-pattern>
18     </servlet-mapping>
19     <session-config>
20         <session-timeout>
21             30
22         </session-timeout>
23     </session-config>
24     <welcome-file-list>
25         <welcome-file>index.xhtml</welcome-file>
26     </welcome-file-list>
27 </web-app>

web.xml文件包含Facelets应用程序所需的几个元素。使用NetBeans IDE创建应用程序时,将自动创建以下所有内容。

  • 指定项目阶段的上下文参数:

        <context-param>
            <param-name>javax.faces.PROJECT_STAGE</param-name>
            <param-value>Development</param-value>
        </context-param>

    上下文参数提供Web应用程序所需的配置信息。应用程序可以定义自己的上下文参数。此外,JavaServer Faces技术和Java Servlet技术定义了应用程序可以使用的上下文参数。

  • 一个servlet元素及其servlet-mapping元素指定 FacesServlet所有带.xhtml后缀的文件都将匹配:

        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>*.xhtml</url-pattern>
        </servlet-mapping>
  • 一个welcome-file-list元素指定着陆页的位置:

        <welcome-file-list>
            <welcome-file>index.xhtml</welcome-file>
        </welcome-file-list>