2012-01-27 121 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