[java web]-- 项目中的web.xml配置详解

实际项目中的举例

举例一

<?xml version="1.0" encoding="GBK"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <!-- 监听器,定时删除文件任务 -->
  <listener>
  <listener-class>com.test.lns.TaskListener</listener-class>
  </listener>
  <!-- UTF-8编码过滤器 -->
<filter>
<filter-name>EncodingFilter</filter-name>
<filter-class>com.test.filter.EncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<!-- Encoding 编码 -->
<context-param>
<param-name>Encoding</param-name>
<param-value>GBK</param-value>
</context-param>

  <!-- struts2核心控制器 -->
 <filter>
  <filter-name>test</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

<!--如果struts.xml文件在src目录下,那么就不用一下标签-->
  <init-param>
  <param-name>config</param-name>
  <param-value>struts-default.xml,struts-plugin.xml,config/test/struts/struts.xml</param-value>
  </init-param>
 </filter>
 <filter-mapping>
  <filter-name>test</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
<!-- JspFilter -->
<filter>
<filter-name>jspfilter</filter-name>
<filter-class>com.test.filter.JspFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>jspfilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
</web-app>

举例二

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <!-- login -->
  <servlet>
  <servlet-name>LoginAction</servlet-name>
  <servlet-class>web.test.controller.login.LoginAction</servlet-class>
  </servlet>
  <servlet-mapping>
  <servlet-name>LoginAction</servlet-name>
  <url-pattern>/login/userLogin</url-pattern>
  </servlet-mapping>
  <!-- 编码值 -->
  <context-param>
  <param-name>Encoding</param-name>
  <param-value>GBK</param-value>
  </context-param>
 <!-- 设置编码过滤器-->
 <filter>
  <filter-name>EncodingFilter</filter-name>
  <filter-class>web.md.filter.EncodingFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>EncodingFilter</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>FORWARD</dispatcher>
 </filter-mapping>
 <!-- 强制登录 -->
 <filter>
  <filter-name>LoginFilter</filter-name>
  <filter-class>web.md.filter.LoginFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>LoginFilter</filter-name>
  <url-pattern>/wumei/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
 </filter-mapping>
 <!-- 监听项目删除日志的程序 -->
 <listener>
  <listener-class>web.md.listener.LogListener</listener-class>
 </listener>
 <!--第一个 监听下发xml和mp3文件的程序 -->
 <listener>
  <listener-class>web.md.listener.HandoutXmlListener</listener-class>
 </listener>
 <!-- 设置session过期时间 ,tomcat默认session有效时间是30min,如果三者有冲突时,有效的级别顺序是:java.setMax****   >xml  > tomcat    -->
 <session-config>
  <session-timeout>30</session-timeout>
 </session-config>
</web-app>

 

举例三

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <display-name></display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

<!--配置struts.xml文件-->
  <filter>
    <filter-name>zpark</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>struts-default.xml,struts-plugin.xml,com/config/struts/struts.xml</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>zpark</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

<!--初始化spring的applicationContext.xml文件-->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
    <param-name>contextConfigLocation</param-name>

<!--applicationContext.xml的全路径-->
    <param-value>classpath:com/config/spring/applicationContext.xml</param-value>
  </context-param>
</web-app>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

往事随风ing

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值