<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_4_0.xsd"
version="4.0">
<display-name>JSP 项目名称</display-name>
<description>JSP 项目描述</description>
<icon> <!--指定web站台中小图标和大图标的路径,图象文件必须为GIF或JPEG的格式,扩展名必须为:gif或jpg-->
<small-icon>小图标路径</small-icon>
<large-icon>大图标路径</large-icon>
</icon>
<!--添加servlet上下文初始化参数,参数名在整个Web应用中必须是惟一的-->
<context-param>
<param-name>param_name</param-name>
<param-value>param_value</param-value>
</context-param>
<!--用于指定Web容器中的过滤器-->
<filter>
<filter-name>Filter名称</filter-name>
<filter-class>指定过滤器类的完全限定的名称</filter-class>
<init-param> <!--和context-param 类似,不过只能在filter中访问到-->
<param-name>encoding</param-name>
<param-value>GB2312</param-value>
</init-param>
</filter>
<!--Web应用中的过滤器映射,过滤器可被映射到一个servlet或一个URL模式-->
<filter-mapping>
<filter-name>Filter名称</filter-name> <!--对应被指定filter的名称-->
<url-pattern>/*</url-pattern> <!--映射模式-->
</filter-mapping>
<!--用于指定Web容器中的servlet-->
<servlet>
<servlet-name>servlet名称</servlet-name>
<servlet-class>指定servlet类的完全限定的名称</servlet-class>
</servlet>
<!--用来定义servlet所对应URL-->
<servlet-mapping>
<servlet-name>servlet名称</servlet-name>
<url-pattern>/login</url-pattern> <!--访问该servlet的url-->
</servlet-mapping>
<!--用来注册一个监听器类,可以在Web应用中包含该类-->
<listener>
<listener-class>指定listener类的完全限定的名称</listener-class>
</listener>
<!--session-config包含一个子元素session-timeout.定义web应用中的session有效时间,单位为分钟-->
<session-config>
<session-timeout>20</session-timeout>
</session-config>
<!--mime-mapping包含两个子元素extension和mime-type,定义某一个扩展名和某一MIME Type做对映-->
<mime-mapping>
<extension>doc</extension> <!--扩展名-->
<mime-type>application/vnd.ms-word</mime-type> <!--MIME格式-->
</mime-mapping>
<mime-mapping>
<extension>xls</extension>
<mime-type>application/vnd.ms-excel</mime-type>
</mime-mapping>
<!--welcome-file-list包含一个子元素welcome-file.用来定义首页列单.-->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file> <!--首页文件名称-->
<welcome-file>index.htm</welcome-file> <!--如果存在多个名称,会依次查找-->
</welcome-file-list>
<!--error-page元素包含三个子元素error-code,exception-type和location.
将错误代码(Error Code)或异常(Exception)的种类对应到web应用资源路径-->
<error-page>
<error-code>404</error-code> <!--错误码-->
<location>/error404.jsp</location> <!--对应的webURL资源路径-->
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type> <!--异常种类-->
<location>/except.jsp</location> <!--对应的webURL资源路径-->
</error-page>
<!--jsp-config元素主要用来设定JSP的相关配置-->
<jsp-config>
<!-- taglib元素包含两个子元素taglib-uri和taglib-location.
用来设定JSP网页用到的Tag Library路径-->
<taglib>
<taglib-uri>Taglib</taglib-uri>
<taglib-location>/WEB-INF/tlds/MyTaglib.tld</taglib-location>
</taglib>
<jsp-property-group>
<description> <!--此设定的说明-->
Special property group for JSP Configuration JSP example.
</description>
<display-name>JSPConfiguration</display-name> <!--此设定的名称-->
<uri-pattern>/*</uri-pattern> <!--设定值影响的范围-->
<el-ignored>true</el-ignored> <!--若为true,表示不支持EL语法-->
<page-encoding>GB2312</page-encoding> <!--设定JSP网页的编码-->
<scripting-inivalid>true</scripting-inivalid> <!--若为true表示不支持<%scription%>语法-->
<include-prelude>.jspf</include-prelude> <!--设置JSP网页的抬头,扩展名为.jspf-->
<include-coda>.jspf</include-coda> <!--设置JSP网页的结尾,扩展名为.jspf-->
</jsp-property-group>
</jsp-config>
<!--利用JNDI(Java命名和目录接口)取得应用可利用资源-->
<resource-ref>
<description>JNDI JDBC DataSource of JSPBook</description> <!--资源说明-->
<res-ref-name>jdbc/sample_db</res-ref-name> <!--资源名称-->
<res-type>javax.sql.DataSoruce</res-type> <!--资源种类-->
<res-auth>Application|Container</res-auth> <!--资源由Application或Container来许可-->
<res-sharing-scope>Shareable|Unshareable</res-sharing-scope> <!--资源是否可以共享.默认值为 Shareable-->
</resource-ref>
</web-app>
Web工程web.xml详解
最新推荐文章于 2022-12-02 15:00:19 发布