您的位置:首页 > 编程语言 > Java开发

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

2015-09-08 19:19 429 查看
实际项目中的举例:

举例一、

<?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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: