下载 urlrewritefilter-4.0.3.jar
1、web.xml中配置
<!--配置Url Rewrite的Filter开始 -->
<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> //urlrewrite.xml的路径
</init-param>
</filter>
<!--配置Url Rewrite的Filter拦截所有请求-->
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--配置Url Rewrite的Filter结束 -->
2、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>^/([0-9_]+).html$</from> //显示的路径 (注意正则表达式)
<to>/website/detail.do?a=$1</to> //实际访问路径
</rule>
</urlrewrite>
outbound-rule配制
将页面的超链接选项转化为伪静态化,如:
http://www.onlyfun.com/goods/company.jsp?companyId=455326 转化为
<outbound-rule>
<from>^/urlrewriteDemo/goods/company.jsp\?companyId=([0-9]+)$</from>
<to>/urlrewriteDemo/company/$1.html</to>
</outbound-rule>
3、页面
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> //需要引入c标签
<body>
<c:url value="/${var.ZXZX_ID}.html" var="tempUrl"></c:url>
<a href="${tempUrl}"></a>
</body>
4、效果
实际访问路径:website/detail.do?a=‘20160622_1’