2010-06-17 35 views
5

Dưới đây là một đoạn MVC-config.xml của tôi:mùa xuân 3,0 MVC MVC: view-controller thẻ

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

Tôi có welcome.jsp on/WEB-INF/xem/thư mục và login.jsp trên/WEB-INF/xem/tĩnh /.

Điều này phù hợp với đường dẫn '/ chỉ mục' và '/ đăng nhập'. Nhưng tôi nhận được phản hồi 404 cho '/ static/login' khi được gọi từ trình duyệt. Tôi hy vọng rằng '/ static/login /' và '/ login' sẽ hoạt động giống nhau.

Điều gì có thể xảy ra ở đây?

Sẽ đánh giá cao bất kỳ trợ giúp nào.

Cảm ơn!

Đây là 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> 

và đây là 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> 

Môi trường: Tôi đang sử dụng SpringSource tc máy chủ Dev phiên bản v2.0
mùa xuân phiên bản: 3.0.3.RELEASE

Trả lời

6

Yêu cầu /static/login không thể nhận được vào DispatcherServlet của bạn, bởi vì nó phù hợp với quy tắc viết lại /static/**-/static/$1 với last = "true", và do đó không phù hợp với quy tắc /**-/app/$1, dẫn đến DispatcherServlet. Xem tài liệu UrlRewriteFilter để biết thêm thông tin.

+0

Tôi bỏ qua phần đó. Nó hiện đang hoạt động. Cảm ơn bạn! – gouki

2

Điều này làm việc tốt cho tôi, bạn có thể cho tôi biết ánh xạ điều phối Servlet của bạn là gì? Sẽ thật tuyệt nếu bạn có thể đính kèm toàn bộ nội dung web.xml.

+0

Tôi đã chỉnh sửa câu hỏi của mình để bao gồm nội dung web.xml và urlrewrite.xml. Cảm ơn! – gouki

Các vấn đề liên quan