首先 加载 urlrewrite包
配置web。xml
[list]
[*]
[/list]
以及 urlrewrite.xml
<a href="test/users/123456">动态传参测试</a>
<a href="test/users/123456/">动态传参测试</a>
<a href="test.html">静态测试</a>
多参数传递
配置web。xml
[list]
[*]
- <error-page>
- [*] <error-code>404</error-code>
- [*] <location>/error.jsp</location>
- [*] </error-page>
- [*]
[/list]
- [list]
- [*] <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>
- [/list]
以及 urlrewrite.xml
- [list]
- [*] <rule>
- [*]
- [*]//或者 <from>^/test/users/([0-9]+).html$</from>
- [*] <from>^/test/users/([0-9]+)(/)?$</from> <!-- (/)? 匹配前面的字符1或0次 匹配 数字结尾的 或者数字/结尾的 11112或 11112/ -->
- [*] <to>/test.jsp?users=$1</to>
- [*] </rule>
- [*]<!-- 静态 -->
- [*] <rule>
- [*] <from>^/test.html</from>
- [*] <to type="forward">/demo.jsp</to>
- [*] </rule>
- [/list]
<a href="test/users/123456">动态传参测试</a>
<a href="test/users/123456/">动态传参测试</a>
<a href="test.html">静态测试</a>
多参数传递
- [list]
- [*] <rule>
- [*] <from>^/test/([0-9]+)/([0-9a-zA-Z]+)$</from> <!-- (/)? 匹配前面的字符1或0次 匹配 数字结尾的 或者数字/结尾的 11112或 11112/ -->
- [*] <to type="forward">/tservert?users=$1&tt=$2</to>
- [*] </rule>
- [*]
- [/list]
- <to>中 & 用&[list]
- [*]
- [/list]
- <?xml version="1.0" encoding="utf-8"?>
- <urlrewrite>
- <!-- 帖子列表 -->
- <rule>
- <from>^/forum-(d+)-(d+).html$</from>
- <to type="forward">/servlet/TopicListServelet?sid=$1&page=$2</to>
- </rule>
- <!-- 帖子列表加分页
- <rule>
- <from>^/subcate_list_(d+).html$</from>
- <to type="forward">/servlet/TopicListServelet?sid=$1</to>
- </rule> -->
- <!-- 帖子详细信息 -->
- <rule>
- <from>^/thread-(d+).html$</from>
- <to type="forward">/servlet/TopicDetailServlet?tid=$1</to>
- </rule>
- </urlrewrite>