1、www.tuckey.org/urlrewrite/ 下載URL Rewrite JAR包
2、將jar包復制到項目WEB-INF/web.xml 下
3、在web.xml中配置URL Rewrite,代碼如下:
<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、添加偽靜態映射規則urlrewrite.xml
<?xml version="1.0" encoding="GBK"?> <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN" "http://tuckey.org/res/dtds/urlrewrite3.2.dtd"> <urlrewrite> <rule> <!-- 所有配置如下正則表達式的請求 --> <from>/hellotag.html</from> <!-- 將被forward到如下JSP頁面,其中$1代表 上面第一個正則表達式所匹配的字符串 --> <to type="forward">/hellotag.jsp</to> </rule> </urlrewrite>