2 qq 30059235 qq_30059235 于 2017.09.04 10:48 提问

请问一下spring mvc 的UrlRewrite的rule怎么配置

我想实现通过index.jsp?id=10000去访问真实路径index.do?id=10000
我的配置
web.xml

 <filter>
            <filter-name>UrlRewriteFilter</filter-name>
            <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
            <!-- 
                设备文件重加载间隔 (0默示随时加载, -1默示不重加载, 默认-1) 
            -->
            <init-param>
                <param-name>confReloadCheckInterval</param-name>
                <param-value>60</param-value>
            </init-param>

            <!-- 自定义配置文件的路径,是相对context的路径,(默认位置 /WEB-INF/urlrewrite.xml) -->
            <init-param>
                <param-name>confPath</param-name>
                <param-value>\WEB-INF\classes\springweb\urlrewrite.xml</param-value>
            </init-param>

            <!-- 
                设置日志级别(将被记录到日志中)
                   可以为: TRACE, DEBUG, INFO (default), WARN, ERROR, FATAL, log4j, commons, slf4j,
                   比如 sysout:DEBUG(设置到控制台调试输出级别) 
                (默认级别 WARN) -->
            <init-param>
                <param-name>logLevel</param-name>
                <param-value>DEBUG</param-value>
            </init-param>
        </filter>

        <filter-mapping>
            <filter-name>UrlRewriteFilter</filter-name>
            <url-pattern>*.jsp</url-pattern>
            <dispatcher>REQUEST</dispatcher>
            <dispatcher>FORWARD</dispatcher>
        </filter-mapping>

urlrewrite.xml

  <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE urlrewrite
    PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
    "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
<urlrewrite>
    <rule>
        <from>index.jsp?id=(.*)$</from>  
        <to>index.do?id=$1</to> 
    </rule>
</urlrewrite>

1个回答

caozhy
caozhy   Ds   Rxr 2017.09.04 17:19
Csdn user default icon
上传中...
上传图片
插入图片