web.xml
的源代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<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>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
一、web.xml部署描述符元素
描述web.xml
了根元素下的模式中定义的部署描述符元素<web-app>
。
使用Java EE
注释,标准web.xml
部署描述符是可选的。根据Servlet 2.5
规范,可以在某些Web组件上定义注释,例如servlet
,过滤器,侦听器和标记处理程序。注释用于声明对外部资源的依赖性。
二、web.xml命名空间声明和模式位置
<web-app version="3.1"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
其中规定了版本、命名空间、与及维护组织和标准地址。
三、context-param
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
可选context-param元素包含Web应用程序的servlet上下文初始化参数的声明。
- param-name:参数名称
- param=value:参数值
四、servlet
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
该servlet元素包含servlet的声明性数据。
如果jsp-file指定了a 且元素存在,那么在WebLogic Server启动时会预编译并加载JSP。
下表描述了可以在元素中定义的servlet元素。
<servlet-name> |
定义servlet的规范名称,用于在部署描述符的其他位置引用servlet定义 |
---|---|
<servlet-class> |
123 |
<load-on-startup> |
用于将定义的安全角色名称链接到servlet逻辑中硬编码的备用角色名称。这个额外的抽象层允许在部署时配置servlet,而无需更改servlet代码。 |
五、servlet-mapping
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
该servlet-mapping元素定义了servlet和URL模式之间的映射。
下表描述了可以在元素中定义的servlet-mapping元素。
servlet-name |
要映射URL模式的servlet的名称。此名称对应于您在声明标记中指定servlet的名称。 |
---|---|
url-pattern |
描述用于解析URL的模式。将http://host:port+ 之后的URL部分WebAppName与WebLogic Server进行比较。如果模式匹配,则将调用此元素中映射的servlet。 |
六、session-config
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
该session-config元素定义此Web应用程序的会话属性。
session-timeout
:此Web应用程序中的会话过期的分钟数。除非输入此处列出的特殊值之一,否则此元素中设置的值将覆盖WebLogic特定部署描述符中元素TimeoutSecs属性中设置的值。weblogic.xml
七、welcome-file-list
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
可选welcome-file-list元素包含有序的welcome-file元素列表。
当URL请求是目录名称时,WebLogic Server将提供此元素中指定的第一个文件。如果找不到该文件,则服务器尝试列表中的下一个文件。