1、下载jar包 http://tuckey.org/urlrewrite/
2、web.xml配置
<!-- url重写begin --> <filter> <filter-name>UrlRewriteFilter</filter-name> <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class> <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> </filter-mapping> <!-- url重写end --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.shtml</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> </filter-mapping>
3、新建xml文件:urlrewrite.xml,放到WEB-INF目录下
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.1//EN" "http://tuckey.org/res/dtds/urlrewrite3.1.dtd"><!-- Configuration file for UrlRewriteFilter http://tuckey.org/urlrewrite/--><urlrewrite> <rule> <note> The rule means that requests to /test/status/ will be redirected to /rewrite-status the url will be rewritten. </note> <from>^/vweb/view/index\-([0-9]+)$</from> <to>/vweb/view/index.shtml?_id=$1</to> </rule></urlrewrite>
类似于:/vweb/view/index-1 这样的请求会被转译成:/vweb/view/index.shtml?_id=1