1.利用maven下载相关jar文件,pom文件配置如下:
<dependency> <groupId>org.tuckey</groupId> <artifactId>urlrewritefilter</artifactId> <version>3.2.0</version> </dependency>
2.在web.xml中配置UrlRewriteFilter,配置如下:
<!--urlrewrite过滤器--> <filter> <filter-name>UrlRewriteFilter</filter-name> <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class> <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>WARN</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.添加urlrewirte.xml文件,将文件放在WEB-INF目录下(貌似该文件只能放在WEB-INF下)。配置如下:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN" "\\urlrewrite3.2.dtd"> <urlrewrite> <rule> <from>^/([A-Za-z0-9]{6})</from> <to type="forward">/jump.html?s=$1</to> </rule> </urlrewrite>
至此,搞定!