如用户输入的url如下,
http://m10.abc.dev/md/10007/123456
需要将其转给aplThirdPartyMembspCard.action处理,该action接收两个请求参数
10007和123456,则可以利用urlrewriter 实现,步骤如下:
1.添加maven依赖
<dependency>
<groupId>org.tuckey</groupId> <artifactId>urlrewritefilter</artifactId> <version>4.0.3</version> </dependency>2.在web.xml添加UrlRewriteFilter(需要置于其他filter的前面)
<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>/md/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> </filter-mapping>3.在WEB-INF文件夹下添加urlrewrite.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite
PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN" "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd"><urlrewrite>
<rule>
<from>^/md/([0-9]+)/([0-9]+)/?$</from> <to type="redirect">/shop/membsp/aplThirdPartyMembspCard.action?t=$1&m=$2&c=sms</to> </rule></urlrewrite>
其中$1表示from中的第一个参数,多个参数直接要用&连接
关于urlrewriter可参阅