urlrewrite.xml似乎不起作用

时间:2011-11-16 04:40:18

标签: java spring spring-mvc url-rewriting

我一直在做一个Spring项目。我希望我的URL写在localhost:8080 / app / main / something而不是localhost:8080 / app / main.htm?type = something。 或者像localhost:8080 / app / employee / input而不是localhost:8080 / employee.htm?type = input,但到目前为止URL仍然是相同的。有人可以帮帮我吗?

这是我的web.xml

        <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>DEBUG</param-value>
            </init-param>
        </filter>

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



      <servlet-mapping>
    <servlet-name>verse</servlet-name>
    <url-pattern>*.htm</url-pattern>
  </servlet-mapping>

这是我的urlrewrite.xml

 <rule>
<from>^/main.htm?type=([a-z]+)$</from>
<to type="redirect">/main/something/</to>
 </rule>

 <rule>
<from>^/inputregion.htm$</from>
<to type="redirect">/main/region/input</to>
 </rule>

我在servlet中的viewResolver:

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
            <property name="prefix" value="/WEB-INF/jsp/"></property>
            <property name="suffix" value=".jsp"></property>                    
        </bean>

1 个答案:

答案 0 :(得分:2)

想通了

<outbound-rule enabled="true">
        <from>^/main\.htm$</from>
        <to type="redirect">/dashboard/</to>

     </outbound-rule>



    <rule enabled="true">
        <from>/dashboard/</from>
        <to>/main.htm</to>
    </rule>