web.xml文件配置的参考代码

 1.<?xml version="1.0" encoding="UTF-8"?>

  2.<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"

  3.xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  4.xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

  5.http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

  6.<!-- 对改WEB应用进行描述 -->

  7.<description>Test</description>

  8.<!-- 显示 -->

  9.<display-name>Test</display-name>

  10.<!-- 定义全局变量 -->

  11.<context-param>

  12.<!-- 描述符 -->

  13. <description>context param</description>

  14. <!-- 参数 -->

  15. <param-name>encoding</param-name>

  16. <!-- 参数值 -->

  17. <param-value>UTF-8</param-value>

  18.</context-param>

  19.

  20.<!-- 定义网站的字符编码方式 -->

  21.<locale-encoding-mapping-list>

  22. <locale-encoding-mapping>

  23. <locale>zh</locale>

  24. <encoding>gb2312</encoding>

  25. </locale-encoding-mapping>

  26.</locale-encoding-mapping-list>

  27.

  28.<!-- 定义过滤器 -->

  29.<filter>

  30.<filter-name>testFilter</filter-name>

  31.<filter-class>com.jonw.filter.TestFilter</filter-class>

  32.<!-- 局部变量,只适用此Filter -->

  33.<init-param>

  34.<param-name>encoding</param-name>

  35.<param-value>UTF-8</param-value>

  36.</init-param>

  37.</filter>

  38.<filter-mapping>

  39.<filter-name>testFilter</filter-name>

  40.<url-pattern>/*</url-pattern>

  41.</filter-mapping>

  42.<!-- 定义一个监听器 -->

  43.<listener>

  44.<listener-class>com.jonw.listener.TestListener</listener-class>

  45.</listener>

  46.<!-- 定义一个验证用户登录的Servlet -->

  47.<servlet>

  48.<servlet-name>login</servlet-name>

  49.<servlet-class>com.jonw.servlet.UserLogin</servlet-class>

  50.</servlet>

  51.<servlet-mapping>

  52.<servlet-name>login</servlet-name>

  53.<url-pattern>/login.do</url-pattern>

  54.</servlet-mapping>

  55.<!-- WEB应用的默认主页 -->

  56.<welcome-file-list>

  57. <welcome-file>index.jsp</welcome-file>

  58.</welcome-file-list>

  59.<!-- 声明数据源,此数据源放在META-INF文件夹下 -->

  60.<resource-ref>

  61. <description>DataSource</description>

  62. <res-ref-name>Jdbc/Connection</res-ref-name>

  63. <res-type>javax.sql.DataSource</res-type>

  64. <res-auth>Container</res-auth>

  65.</resource-ref>

  66.<!-- 定义Session的超时时间,在这里定义一分钟 -->

  67.<session-config>

  68. <session-timeout>30</session-timeout>

  69.</session-config>

  70.<!-- 设置JSP的各属性 -->

  71.<jsp-config>

  72. <jsp-property-group>

  73. <!-- 应用范围 -->

  74. <url-pattern>/*</url-pattern>

  75. <!-- 是否支持EL表达式 -->

  76. <el-ignored>false</el-ignored>

  77. <!-- 是否技技页面JAVA代码 -->

  78. <scripting-invalid>false</scripting-invalid>

  79. </jsp-property-group>

  80.</jsp-config>
81.<!-- 定义页面没找到时,由容器指向哪个页面 -->

  82.<error-page>

  83. <error-code>404</error-code>

  84. <location>/without.jsp</location>

  85.</error-page>

  86.<!--定义整个WEB应用出现空指向异常所指向哪个页面-->

  87.<error-page>

  88. <exception-type>java.lang.NullPointerException</exception-type>

  89. <location>/null.jsp</location>

  90.</error-page>

  91.<!-- 设置整个WEB站点的图标,即浏览器URL左边的图标 -->

  92.<icon>

  93. <!-- 大图标 -->

  94. <small-icon>/images/small.jpg</small-icon>

  95. <!-- 小图标 -->

  96. <large-icon>/images/large.jpg</large-icon>

  97.</icon>

  98.<!-- 避免浏览器打开以下格式的文件。 -->

  99.<mime-mapping>

  100. <extension>xls</extension>

  101. <mime-type>application/msexcel</mime-type>

  102.</mime-mapping>

  103.<mime-mapping>

  104. <extension>doc</extension>

  105. <mime-type>application/msword</mime-type>

  106.</mime-mapping>

  107.<!-- WEB应用安全的配置 -->

  108.<security-constraint>

  109. <!-- 显示 -->

  110. <display-name>security realm</display-name>

  111. <!-- 安全方式 -->

  112. <web-resource-collection>

  113. <!-- 可以吓写,不用管 -->

  114. <web-resource-name>all role access</web-resource-name>

  115. <!-- 应用WEB应用的所有文件 -->

  116. <url-pattern>/*</url-pattern>

  117. <!-- 定义有哪几种访问方式 -->

  118. <http-method>GET</http-method>

  119. <http-method>POST</http-method>

  120. <http-method>DELETE</http-method>

  121. <http-method>PUT</http-method>

  122. </web-resource-collection>

  123. <!-- 定义哪些用户有访问权限 -->

  124. <auth-constraint>

  125. <role-name>wang</role-name>

  126. <role-name>admin</role-name>

  127. </auth-constraint>

  128. <!-- 用户数据约述 -->

  129. <user-data-constraint>

  130. <transport-guarantee>NONE</transport-guarantee>

  131. </user-data-constraint>

  132.</security-constraint>

  133.<!-- 声明有多少个用户,当然此用户必须在/conf/tomcat-user.xmL文件中存在, -->

  134.<security-role>

  135. <description>role</description>

  136. <role-name>wang</role-name>

  137.</security-role>

  138.<!-- 声明有多少个用户,当然此用户必须在/conf/tomcat-user.xmL文件中存在, -->

  139.<security-role>

  140. <description>role</description>

  141. <role-name>admin</role-name>

  142.</security-role>

  143.<!-- 声明有多少个用户,当然此用户必须在/conf/tomcat-user.xmL文件中存在, -->

  144.<security-role>

  145. <description>role</description>

  146. <role-name>manager</role-name>

  147.</security-role>

  148.<!-- 用户登录 -->

  149.<login-config>

  150. <!-- 用户登录方式 -->

  151. <auth-method>FORM</auth-method>

  152. <!-- 登录界面,这个与登录方式有关联 -->

  153. <form-login-config>

  154. <form-login-page>/login.jsp</form-login-page>

  155. <form-error-page>/login-Error.jsp</form-error-page>

  156. </form-login-config>

  157.</login-config>

  158.</web-app>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值