Urlrewrite与Struts2.x结合使用

之前在struts1.x中就已经使用过urlrewrite(下载地址 http://tuckey.org/urlrewrite/#download)这个jar包的了,有这个urlrewrite的目的就是为了简化与美观及对SEO,搜索引擎收录等方面都有好处。

最近改版系统,由struts1.x升级为struts2.x,在使用时urlrewrite这个时,直接将xml文件及jar复制过来,然后就开始运行,但好遗憾的时,没有起到作用,于是上网查,查到一大堆的资料,基本上都是说加多两个配置选项,于是一样的照抄过,所以我的WEB.XML文件的配置如下(过滤器部分):
<!-- 字符过滤器 -->
	<filter>
		<filter-name>encodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
		<init-param>
			<param-name>forceEncoding</param-name>
			<param-value>true</param-value>
		</init-param>
	</filter>	
	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	
	<!-- Hibernate Open Session In View filter(开启OSIV)-->
	<filter>
		<filter-name>hibernateOpenSessionInViewFilter</filter-name>
		<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>hibernateOpenSessionInViewFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	
	<!-- UrlRewriteFilter简化URL,有利于搜索引擎收录 -->
	 <filter>
        <filter-name>UrlRewriteFilter</filter-name>
        <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
         <init-param>
            <param-name>logLevel</param-name>
            <param-value>WARN</param-value>
        </init-param>
	</filter>		 
	  <filter-mapping>
        <filter-name>UrlRewriteFilter</filter-name>
        <url-pattern>/*</url-pattern>
     </filter-mapping>
     
	<!-- Struts2 核心过滤器 -->
	<filter>
		<filter-name>struts2CleanupFilter</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>struts2CleanupFilter</filter-name>
		<url-pattern>/*</url-pattern>				
		<dispatcher>REQUEST</dispatcher>  
		<dispatcher>FORWARD</dispatcher>
		<dispatcher>INCLUDE</dispatcher>
	</filter-mapping>
	
	<filter>
		<filter-name>struts2Filter</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>struts2Filter</filter-name>
		<url-pattern>/*</url-pattern>		
		<dispatcher>REQUEST</dispatcher>  
		<dispatcher>FORWARD</dispatcher>
		<dispatcher>INCLUDE</dispatcher>
	</filter-mapping>


保存,运行,还是不成功!感觉就好似urlrewrite.jar这个包没启动成功一样,但我已经时时按网上的配置配好的了,加载顺序为:
1, encodingFilter
2, opensessionInviewfilter
3, UrlRewriteFilter
4, struts2-Cleanup
5, struts2

这已经是没有错的了,为什么会不成功的呢?于是再google,终于在 http://wiki.springside.org.cn/display/SpringSide3/View这个页里看到一句:
首先在web.xml中加入url rewrite filter,注意需放到struts2 filter的前面,然后在WEB-INF/下放一个urlrewrite.xml进行定义
,然后在WEB-INF/下放一个urlrewrite.xml, 于是马上查看了一下,发现我自己的竟然写在src目录下,那些在WEB-INF目录下就是在classes生成urlrewrite.xml,于是将src目录下的删除,再将classes目录下移至WEB-INF目录下再运行。

泪奔中.....实在太操心意了。

你可能感兴趣的:(apache,xml,Hibernate,Web,搜索引擎)