当前位置: 代码迷 >> Java相关 >> urlrewrite组合struts2
  详细解决方案

urlrewrite组合struts2

热度:144   发布时间:2016-04-22 20:00:42.0
urlrewrite结合struts2

1、下载jar包 http://tuckey.org/urlrewrite/

2、web.xml配置

    <!-- url重写begin -->    <filter>        <filter-name>UrlRewriteFilter</filter-name>        <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>        <init-param>            <param-name>logLevel</param-name>            <param-value>WARN</param-value>        </init-param>    </filter>    <filter-mapping>        <filter-name>UrlRewriteFilter</filter-name>        <url-pattern>/*</url-pattern>    </filter-mapping>    <!-- url重写end -->        <filter>        <filter-name>struts2</filter-name>        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>    </filter>    <filter-mapping>        <filter-name>struts2</filter-name>        <url-pattern>*.shtml</url-pattern>        <dispatcher>REQUEST</dispatcher>           <dispatcher>FORWARD</dispatcher>             </filter-mapping>

3、新建xml文件:urlrewrite.xml,放到WEB-INF目录下

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.1//EN"        "http://tuckey.org/res/dtds/urlrewrite3.1.dtd"><!--    Configuration file for UrlRewriteFilter    http://tuckey.org/urlrewrite/--><urlrewrite>         <rule>        <note>            The rule means that requests to /test/status/ will be redirected to /rewrite-status            the url will be rewritten.        </note>        <from>^/vweb/view/index\-([0-9]+)$</from>        <to>/vweb/view/index.shtml?_id=$1</to>    </rule></urlrewrite>

类似于:/vweb/view/index-1 这样的请求会被转译成:/vweb/view/index.shtml?_id=1

  相关解决方案