Spring 3.0 MVC mvc:view-controller tag
Here's a snippet of my 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"/>
I have the welcome.jsp on /WEB-INF/view/ directory and login.jsp on /WEB-INF/view/static/.
This works for '/index' and '/login' paths. But I'm getting 404 response for '/static/login' when invoked from the browser. I'm expecting that '/static/login/' and '/login' should behave the same.
What could be wrong here?
Would appreciate any help.
Thanks!
Here's the 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>
and here is the 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>
Environment: I'm using SpringSource tc Server Dev Edition v2.0
Spring version: 3.0.3.RELEASERequest for /static/login
can't get into your DispatcherServlet, because it matches the rewriting rule from /static/**
to /static/$1
with last = "true"
, and therefore doesn't match the rule from /**
to /app/$1
, which leads to DispatcherServlet. See UrlRewriteFilter docs for more info.
This is working fine for me, can you tell me what is your Dispatcher Servlet mappings? It would be nice if you can attach the entire web.xml content.
精彩评论