标签:
重写 URL 的好处有很多:
1. Maven 依赖
<dependency> <groupId>org.tuckey</groupId> <artifactId>urlrewritefilter</artifactId> <version>4.0.4</version> </dependency>
2. 配置 web.xml:
<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> </filter-mapping>
3. 配置 /WEB-INF/urlrewrite.xml:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.6//EN" "http://tuckey.org/res/dtds/urlrewrite2.6.dtd"> <urlrewrite> <rule> <from>/items/([0-9]+).html$</from> <to>/items.action?item=$1</to> </rule> <rule> ... </rule> </urlrewrite>
4. 当在浏览器键入 http://www.yourapp.com/items/9999.html 时,请求会被提交至 http://www.yourapp.com/items.action?item=9999
Servlet & JSP - UrlRewriteFilter
标签:
原文地址:http://www.cnblogs.com/huey/p/5478320.html