2010-06-17 83 views
5

這裏是我的MVC-config.xml中的一個片段:春3.0 MVC MVC:視圖 - 控制器標籤

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

我中的welcome.jsp上/ WEB-INF /視圖/目錄上的login.jsp/WEB-INF /視圖/靜態/。

這適用於'/ 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服務器開發版V2.0
春天版本:3.0.3.RELEASE

回答

6

請求/static/login不能進入你的DispatcherServlet的,因爲它與從/static/**/static/$1last = "true"重寫規則,因此不匹配/**/app/$1規則,從而導致的DispatcherServlet。有關更多信息,請參閱UrlRewriteFilter文檔。

+0

我忽略了那部分。它正在工作。謝謝! – gouki 2010-06-21 03:18:42

2

這對我來說工作得很好,你能告訴我什麼是你的Dispatcher Servlet映射嗎?如果您可以附加整個web.xml內容,那就太好了。

+0

我編輯了我的問題以包含web.xml內容和urlrewrite.xml。謝謝! – gouki 2010-06-17 08:54:08