Spring 3.0 MVC mvc:view-controller标签

时间:2010-06-17 07:17:04

标签: spring spring-mvc

这是我的mvc-config.xml的片段:

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

<mvc:view-controller path="/index" view-name="welcome"/>    
<mvc:view-controller path="/static/login" view-name="/static/login"/>   
<mvc:view-controller path="/login" view-name="/static/login"/>

/ WEB-INF / view /目录下的welcome.jsp和/ WEB-INF / view / static /上的login.jsp。

这适用于'/ index'和'/ login'路径。但是当我从浏览器调用时,我得到了'/ static / login'的404响应。我期待'/ static / login /'和'/ login'的行为应该相同。

这里可能有什么问题?

感谢任何帮助。

谢谢!

这是web.xml:

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
    </context-param>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <!-- Enables clean URLs with JSP views e.g. /welcome instead of /app/welcome -->
    <filter>
        <filter-name>UrlRewriteFilter</filter-name>
        <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>UrlRewriteFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Handles all requests into the application -->
    <servlet>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/spring/*.xml
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Maps all /app requests to the DispatcherServlet for handling -->
    <servlet-mapping>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <url-pattern>/app/*</url-pattern>
    </servlet-mapping>

</web-app>

这是urlrewrite.xml:

<urlrewrite default-match-type="wildcard">
    <rule>
        <from>/</from>
        <to>/app/welcome</to>
    </rule>
    <rule>
        <from>/static/**</from>
        <to last="true">/static/$1</to>
    </rule>

    <rule>
        <from>/**</from>
        <to last="true">/app/$1</to>
    </rule>
    <outbound-rule>
        <from>/app/**</from>
        <to>/$1</to>
    </outbound-rule>    
</urlrewrite>

环境: 我正在使用SpringSource tc Server Dev Edition v2.0
春季版:3.0.3.RELEASE

2 个答案:

答案 0 :(得分:6)

请求/static/login无法进入您的DispatcherServlet,因为它与/static/**/static/$1的重写规则与last = "true"匹配,因此与从/**/app/$1的规则,导致DispatcherServlet。有关详细信息,请参阅UrlRewriteFilter文档。

答案 1 :(得分:2)

这对我来说很好,你能告诉我你的Dispatcher Servlet映射是什么吗?如果您可以附加整个web.xml内容,那就太好了。