2010-06-17 39 views
5

He aquí un fragmento de mi mvc-config.xml:Spring 3.0 MVC MVC: etiqueta vista-controlador

<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"/> 

tengo el welcome.jsp en/WEB-INF/vista/y en login.jsp/WEB-INF/view/static /.

Esto funciona para las rutas '/ index' y '/ login'. Pero recibo una respuesta 404 para '/ static/login' cuando se invoca desde el navegador. Estoy esperando que '/ static/login /' y '/ login' se comporten igual.

¿Qué podría estar mal aquí?

Agradecería cualquier ayuda.

Gracias!

Aquí está el 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> 

y aquí está la 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> 

Medio Ambiente: estoy usando SpringSource tc servidor Dev Edición v2.0
primavera versión: 3.0.3.RELEASE

Respuesta

6

Solicitud de /static/login no puede entrar en su DispatcherServlet, porque coincide con la regla de reescritura /static/**-/static/$1 con last = "true", y por lo tanto no coincide con la regla a partir de /** a /app/$1, lo que conduce a DispatcherServlet. Consulte UrlRewriteFilter documentos para obtener más información.

+0

Pasé por alto esa parte. Ahora está funcionando. ¡Gracias! – gouki

2

Esto está funcionando bien para mí, ¿me puede decir cuáles son sus asignaciones de Servlet Dispatcher? Sería bueno si puedes adjuntar todo el contenido web.xml.

+0

He editado mi pregunta para incluir contenido web.xml y urlrewrite.xml. ¡Gracias! – gouki