一、struts2回顾
1.web.xml
作用:用来配置过滤器,欢迎页,错误页,监听器,控制器,log4J的配置,application.xml文件的位置配置,制定中文编码UTF-8的配置等等,以下做详细总结。
a.log4j的配置(log4j是一个非常强大的log记录软件)
log4jConfigLocation
/WEB-INF/log4j.properties
log4jRefreshInterval
60000
log4j:log4jRefreshInterval为60000表示 开一条watchdog线程每60秒扫描一下配置文件的变化;
这里有一片文章详细地讲解了log4j的配置及用法。
http://blog.youkuaiyun.com/azheng270/article/details/2173430/
b.contextConfigLocation的详细解读
转:http://blog.youkuaiyun.com/zndxlxm/article/details/8711626
在web.xml中通过contextConfigLocation配置spring,contextConfigLocation
参数定义了要装入的 Spring 配置文件。
如果想装入多个配置文件,可以在
标记中用逗号作分隔符。
contextConfigLocation
/WEB-INF/applicationContext_mysql.xml
c.解决中文乱码问题
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
encodingFilter
/*
d. HibernateSession开关控制配置
OpenSessionInView
org.springframework.orm.hibernate4.support.OpenSessionInViewFilter
singleSession
true
</filter>
<filter-mapping>
<filter-name>OpenSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
e.配置spring
为了让web应用能加载spring,设置一个侦听,通过这样一个监听器,一启动WEB应用它自动根据上面设置好的配置文件的位置把配置文件加载到内存中,为进一步使用spring中的bean做好准备
org.springframework.web.context.ContextLoaderListener
60
f. 区分servlet与struts2
ReDispatcherFilter
com.sysgrrj.common.ReDispatcherFilter
includeServlets
connector,downfile
g.使Struts2与Servlet并存解决办法 Filter转发Servlet
http://www.cnblogs.com/jifeng/archive/2010/08/28/1810706.html
http://hi.baidu.com/xingsl/item/6df32fa78c0b7112a8cfb754
解决办法:
在Struts2过滤器前增加一个过滤器,使用过滤器转发到servlet
ReDispatcherFilter
*.jsp
ReDispatcherFilter
*.action
ReDispatcherFilter
/
ReDispatcherFilter
/index
ReDispatcherFilter
/fckeditor/editor/filemanager/browser/default/connectors/jsp/connector
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
h.
在 WEB.XML配置实现浏览器根据文件类型自动打开
doc
application/msword
xls
application/msexcel
ppt
application/vnd.ms-powerpoint
wsdl
text/xml