`

struts2重写url,实现伪静态

 
阅读更多
1,在web.xml中加入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>/*</url-pattern>
    </filter-mapping>
并且修改struts2的filter配置:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>
struts-default.xml,struts-plugin.xml,struts.xml
</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.htm</url-pattern>
<dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
</filter-mapping>
2,在WEB-INF目录下加入urlrewrite.xml文件,配置如下:
<urlrewrite>
  
<rule>
<from>/([a-z]+)/([0-9]+).shtml$</from>
<to type= "forward">/$1.htm?id=$2</to>
</rule>
</urlrewrite>
3,在页面中路径写from的样子。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics