java web项目中urlRewrite的使用
1. 首先下载urlRewrite的jar包
2. 将urlRewrite.jar放到WEB-INF/lib中
3. 在WEB-INF/web.xml配置UrlRewriteFilter
<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>
4. 在WEB-INF/urlrewrite.xml 中写入rewrite规则
<urlrewrite>
<rule>
<from>^/$</from>
<to>/homeIndex.do</to>
</rule>
<rule>
<from>^/downloadCenter.html$</from>
<to>/toDownloadCenter.do</to>
</rule>
<rule>
<from>^/downloadCenter-([0-9]+)-([0-9]+).html$</from>
<to>/toDownloadCenter.do?page.pageNo=$1&page.totalPage=$2</to>
</rule>
<rule>
<from>^/downloadDoc/([0-9]+).html$</from>
<to>/toDownloadDoc.do?docId=$1</to>
</rule>
</urlrewrite>
5.启动web服务器。此时如果访问http://原网站已经失效 就相当于访问http://原网站已经失效/homeIndex.do