咨询热线:4006-75-4006
售前:9:00-23:30 备案:9:00-18:00 技术:7*24h
1、web.xml加以下代码
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.do</url-pattern>
<dispatcher>REQUEST</dispatcher> <!--struts2必须配置的-->
<dispatcher>FORWARD</dispatcher> <!--struts2必须配置的-->
</filter-mapping>
<!-- 配置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> <!-- urlrewrite.xml的路径 -->
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher> <!-- 貌似可以不加 -->
<dispatcher>FORWARD</dispatcher> <!-- 貌似可以不加 -->
</filter-mapping>
2、在web-inf下创建urlrewrite.xml(注意urlrewrite必需小写)
在文件里输入以下内容
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.1//EN" "http://www.landui.com/res/dtds/urlrewrite3.1.dtd">
<urlrewrite>
<rule>
<note>用户</note> <!--描述-->
<from>^/user_([_0-9a-zA-Z])+.html$</from> <!--伪地址,你发送请求的地址(访问user_1.html代表访问get_users.do?id=1)-->
<to>/get_users.do?id=$1</to> <!--真实的请求地址$1代表上面正则表达式里的参数-->
</rule>
<rule>
<note>用户</note> <!--描述-->
<from>/aaa.abc</from> <!--伪地址,你发送请求的地址(访问aaa.abc代表访问index.jsp)-->
<to>/index.jsp</to> <!--真实的地址-->
</rule>
</urlrewrite>