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