UrlReWriteFilter 是一個不錯的URL轉換工具,能夠將服務器上存在的文件轉換成想要的任何URL路徑。 首先在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> 再在web.xml同級目錄下創建一個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>/2th</from> <to type="redirect">%{context-path}/second.jsp</to> </rule> <rule> <from>([a-z]+)/([a-z]+).html</from> <to>$1.jsp?page=$2</to> </rule> <outbound-rule> <from>/second.jsp</from> <to>/2th</to> </outbound-rule> </urlrewrite>