2012-01-27 161 views
0

以下情況:我正在用Spring Roo 1.1(Apache Tiles & Spring MVC)開發Web應用程序。我想有一個管理部分,其中每個實體可通過路徑到達(/ admin/users,/ admin/roles,...)Spring MVC靜態頁面

到目前爲止一切工作正常。唯一的問題是,我想在/ admin上有一個靜態頁面。因爲我不希望創建一個自己的控制器我在webmvc-config.xml中補充說:

<mvc:view-controller path="/admin" view-name="admin/index" /> 

另外,在目錄中的WEB-INF /視圖/管理/ views.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN" "http://tiles.apache.org/dtds/tiles-config_2_1.dtd"> 
<tiles-definitions> 
    <definition extends="default" name="admin/index"> 
     <put-attribute name="body" value="/WEB-INF/views/admin/index.jspx"/> 
    </definition> 
</tiles-definitions> 

我也沒有忘記創建一個index.jspx。

內容的web.xml:

<display-name>reservation</display-name> 

<description>Roo generated reservation application</description> 


<!-- Enable escaping of form submission contents --> 
<context-param> 
    <param-name>defaultHtmlEscape</param-name> 
    <param-value>true</param-value> 
</context-param> 

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

<filter> 
    <filter-name>CharacterEncodingFilter</filter-name> 
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 
    <init-param> 
     <param-name>encoding</param-name> 
     <param-value>UTF-8</param-value> 
    </init-param> 
    <init-param> 
     <param-name>forceEncoding</param-name> 
     <param-value>true</param-value> 
    </init-param> 
</filter> 



<filter> 
    <filter-name>HttpMethodFilter</filter-name> 
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> 
</filter> 



<filter> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 
<filter> 
    <filter-name>Spring OpenEntityManagerInViewFilter</filter-name> 
    <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>CharacterEncodingFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

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



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

<!-- Creates the Spring Container shared by all Servlets and Filters --> 
<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

<!-- Handles Spring requests --> 
<servlet> 
    <servlet-name>reservation</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring/webmvc-config.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>reservation</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

<session-config> 
    <session-timeout>10</session-timeout> 
</session-config> 

<error-page> 
    <exception-type>java.lang.Exception</exception-type> 
    <location>/uncaughtException</location> 
</error-page> 

<error-page> 
    <error-code>404</error-code> 
    <location>/resourceNotFound</location> 
</error-page> 

不幸的是請求/管理時,我得到錯誤未找到資源。

有人可以給我一個提示嗎?

+0

其他頁面是否正確呈現?一個問題可能是你的視圖解析器配置,但如果你可以訪問其他頁面,那麼我不會去尋找它。 – 2012-01-27 13:15:19

+0

一切工作完美。我沒有碰到配置文件。 – rainerhahnekamp 2012-01-27 17:30:36

+0

好吧,它似乎表現得非常嚴格。請求「/ admin」工作正常,但「/ admin /」不是。在我原來的文章中,我曾說過我要求「/ admin」,因爲它是「/ admin /」,所以不是這樣的... – rainerhahnekamp 2012-02-06 10:54:39

回答

0

請確保您在您的XML配置中定義了<mvc:annotation-driven />

+0

它用屬性conversion-service =「applicationConversionService」 – rainerhahnekamp 2012-01-27 17:31:06