Java Web Project 的 web.xml 中 Struts2、Spring 配置与过滤器添加需知
2010-07-17 10:51
591 查看
<?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">
<display-name>Luke</display-name>
<!-- Template -->
<!-- ××××××××××××××× Start ××××××××××××××× -->
<!-- ×××××××××××××××× End ×××××××××××××××× -->
<!-- ××××××××××××××× Spring配置和监听 Start ××××××××××××××× -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.content.ContextLoaderListener</listener-class>
</listener>
<!-- ×××××××××××××××× Spring配置和监听 End ×××××××××××××××× -->
<!-- ××××××××××××××× 过滤器(Filter)编写须知 Start ××××××××××××××× -->
<!--
A.单个filter要与多个路径匹配的话要写多个对应的filter mapping
B.其它过滤器必须放在Struts2过滤器的前面,否则无效
-->
<!--
过滤器映射规则
1.优先精确路径匹配:
以/*和/Test为例,Http://localhost:8080/Test会优先找到/Test
同理,长路径匹配也跟精确路径匹配一样,/Test/*和/Test/a/*会优先匹配后者
以斜杠加星结尾或者以斜杠加路径结尾的都是路径匹配
2.扩展匹配:
*.action和*.do之类的扩展名匹配,哪个精确匹配哪个
星加点"*."符号是定义扩展名匹配
3.默认匹配:
当找不到符合匹配的servlet并且设定了Default servlet,请求将被扔给Default servlet
正常的单个"/"符号就是定义Default servlet
-->
<!-- ×××××××××××××××× 过滤器(Filter)编写须知 End ×××××××××××××××× -->
<!-- ××××××××××××××× OpenSessionInViewFilter配置 Start ××××××××××××××× -->
<!--
OpenSessionInViewFilter是Spring对Hibernate令人头痛的Session关闭延迟问题提供的支持
它有初始化参数(init-param)singleSession,默认是true,
如果设为false那这个过滤器就跟没用一个样了,可以作为设定开关。
-->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- ×××××××××××××××× OpenSessionInViewFilter配置 End ×××××××××××××××× -->
<!-- ××××××××××××××× Struts2过滤器 Start ××××××××××××××× -->
<!--
使用StrutsPrepareAndExecuteFilter为Struts2的过滤器,
StrutsPrepareAndExecuteFilter已经成为官方推荐的过滤器
代替原来的FilterDispatcher初始化并处理WEB请求
-->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- ×××××××××××××××× Struts2过滤器 End ×××××××××××××××× -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lukelsq/archive/2010/02/26/5330605.aspx
<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">
<display-name>Luke</display-name>
<!-- Template -->
<!-- ××××××××××××××× Start ××××××××××××××× -->
<!-- ×××××××××××××××× End ×××××××××××××××× -->
<!-- ××××××××××××××× Spring配置和监听 Start ××××××××××××××× -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.content.ContextLoaderListener</listener-class>
</listener>
<!-- ×××××××××××××××× Spring配置和监听 End ×××××××××××××××× -->
<!-- ××××××××××××××× 过滤器(Filter)编写须知 Start ××××××××××××××× -->
<!--
A.单个filter要与多个路径匹配的话要写多个对应的filter mapping
B.其它过滤器必须放在Struts2过滤器的前面,否则无效
-->
<!--
过滤器映射规则
1.优先精确路径匹配:
以/*和/Test为例,Http://localhost:8080/Test会优先找到/Test
同理,长路径匹配也跟精确路径匹配一样,/Test/*和/Test/a/*会优先匹配后者
以斜杠加星结尾或者以斜杠加路径结尾的都是路径匹配
2.扩展匹配:
*.action和*.do之类的扩展名匹配,哪个精确匹配哪个
星加点"*."符号是定义扩展名匹配
3.默认匹配:
当找不到符合匹配的servlet并且设定了Default servlet,请求将被扔给Default servlet
正常的单个"/"符号就是定义Default servlet
-->
<!-- ×××××××××××××××× 过滤器(Filter)编写须知 End ×××××××××××××××× -->
<!-- ××××××××××××××× OpenSessionInViewFilter配置 Start ××××××××××××××× -->
<!--
OpenSessionInViewFilter是Spring对Hibernate令人头痛的Session关闭延迟问题提供的支持
它有初始化参数(init-param)singleSession,默认是true,
如果设为false那这个过滤器就跟没用一个样了,可以作为设定开关。
-->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- ×××××××××××××××× OpenSessionInViewFilter配置 End ×××××××××××××××× -->
<!-- ××××××××××××××× Struts2过滤器 Start ××××××××××××××× -->
<!--
使用StrutsPrepareAndExecuteFilter为Struts2的过滤器,
StrutsPrepareAndExecuteFilter已经成为官方推荐的过滤器
代替原来的FilterDispatcher初始化并处理WEB请求
-->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- ×××××××××××××××× Struts2过滤器 End ×××××××××××××××× -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lukelsq/archive/2010/02/26/5330605.aspx
相关文章推荐
- 怎么在web.xml配置spring,struts2配置以及过滤器
- 如何在web.xml配置spring,struts2配置以及过滤器
- Spring web基于javaconfig类配置 的web.XML配置
- spring整合struts2之web.xml配置
- Java Struts2: 没有 Action 映射的原因可能是 web.xml 中缺乏 welcom-file-list 所配置的页面
- spring与struts2 mvc共存web.xml简单配置
- spring与struts2 mvc共存web.xml简单配置
- web.xml配置struts过滤器struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter和FilterDispatcher的区别
- SpringMVC+Spring4+hibernate5使用java类配置spring和springmvc环境(不用配置web.xml)
- Java_Web Project_web.xml参数配置、servlet配置;
- java文件读取web-inf下的spring的xml配置文件
- SSH框架整合的时候 在web.xml中需配置的spring信息与struts2的配置信息
- java注解方式(不用xml)配置web框架spring+SpringMVC
- struts2需要在web.xml中配置的过滤器
- struts2 的web.xml 配置文件报错org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69)
- Struts2 + Spring + Hibernate 整合 web.xml的一般配置
- SSH开发环境的配置:web.xml、Spring集成hibernate和Spring集成Struts2
- struts2 2.5以上版本安装中web.xml的配置(包括核心过滤器filter)
- struts2整合spring 时web.xml的配置
- struts2与spring整合web.xml加入的配置