UrlRewriteFilter(3.2.0)整理(xj2011-10-31)
Jar包下载网址
http://www.tuckey.org/urlrewrite/
http://code.google.com/p/urlrewritefilter/
当前环境Ecplise + maven
实现UrlRewriteFilter功能步骤
- Download the zip and extract it into your context's directory ie, so that urlrewrite.xml goes into the WEB-INF directory.
- Add the following to your WEB-INF/web.xml (add it near the top above your servlet mappings (if you have any)): (see filter parameters for more options)
<filter>
<filter-name>UrlRewriteFilter</filter-name> <filter-class>
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
3.Add your own configuration to the WEB-INF/urlrewrite.xml that was created.
4.Restart the context
当前环境下操作
1.在mavenpom.xml 文件 dependencies标签下添加
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>3.2.0</version>
</dependency>
2.在WEB-INF/web.xml配置文件中添加urlrewrite过滤器
<filter>
<filter-name>UrlRewriteFilter</filter-name> <filter-class>
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
</filter-class>
<!-- 设置定时检查配置文件的时间以供重新加载时间,该参数值为整型,0为每次都检查,-1为重不检查,默认为-1 -->
<init-param>
<param-name>confReloadCheckInterval</param-name>
<param-value>60</param-value>
</init-param>
<!-- 配置文件路径,默认为default/WEB-INF/urlrewrite.xml-->
<init-param>
<param-name>confPath</param-name>
<param-value>/WEB-INF/urlrewrite.xml</param-value>
/init-param>
<!-- 设置日志等级 -->
<init-param>
<param-name>logLevel</param-name>
<param-value>DEBUG</param-value>
</init-param>
<!-- 设置host的列表,可以使用通配符,多个host用逗号分隔默认localhost,127.0.0.1,local -->
<init-param>
<param-name>statusEnabledOnHosts</param-name>
<param-value>localhost,*.xiu.com</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
3..下载urlrewritefilter-3.2.0.zip解压把WEB-INF/urlrewrite.xml复制到项目中WEB-INF/目录下,参考urlrewrite.xml现有配置,根据项目路径需求更改urlrewrite.xml配置文件
http://localhost:8983/so/search.action?q=a 的效果用
代替
<rule>
<from>/search/([a-z]+).html</from>
<to>/search.action?q=$1</to>
</rule>
3. 启动服务器测试
2011-11-1 11:19:28org.apache.catalina.core.ApplicationContext log
信息: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Rule 0 run called with/search.action 出现org.tuckey.web.filters.urlrewrite.RuleBaseDEBUG 则价值过滤器成功
访问http://localhost:8983/so/search/a.html实现http://localhost:8983/so/search.action?q=a