瓷砖不起作用,没有错误

时间:2014-09-23 20:27:24

标签: java xml spring maven tiles

我尝试使用spring 3.2.5配置tiles 3.0.4,当我返回tiles-definitions.xml中定义的视图时,我收到错误404并且在控制台中没有错误。

这是配置

的pom.xml

 <!-- Web -->
    <jsp.version>2.2</jsp.version>
    <jstl.version>1.2</jstl.version>
    <servlet.version>2.5</servlet.version>
    <tiles-version>3.0.4</tiles-version>
    <!-- Spring -->
    <spring-framework.version>3.2.5.RELEASE</spring-framework.version>
    <spring-data-jpa.version>1.4.2.RELEASE</spring-data-jpa.version>
    <spring-security.version>3.1.4.RELEASE</spring-security.version>

<!-- TILES -->
    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-core</artifactId>
        <version>${tiles-version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-api</artifactId>
        <version>${tiles-version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-jsp</artifactId>
        <version>${tiles-version}</version>
    </dependency>

瓦片-definitions.xml中

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
   "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
   "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>

<definition name="base" template="/WEB-INF/template/layout.jsp">
    <put-attribute name="header" value="/WEB-INF/template/head.jsp" />
    <put-attribute name="menu" value="/WEB-INF/template/navbar.jsp" />
    <put-attribute name="body" value="" />
    <put-attribute name="footer" value="/WEB-INF/template/footer.jsp" />
</definition>

<definition name="route/home" extends="base">
    <put-attribute name="body" value="/WEB-INF/route/list.jsp" />
</definition>

</tiles-definitions>

Spring view resolver - mvc-dispatcher-servlet.xml

<!-- TILES -->
<bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass">
        <value>
            org.springframework.web.servlet.view.tiles3.TilesView
        </value>
    </property>
</bean>

<bean id="tilesConfigurer"
    class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/tiles/tiles-definitions.xml</value>
        </list>
    </property>
</bean>

控制器方法

@RequestMapping(method = RequestMethod.GET)
public String getRoutes(ModelMap model) {
    return "route/home";
}

和servlet配置

 <servlet>
    <servlet-name>name</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/mvc-dispatcher-servlet.xml
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

我无法解决这个问题。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

可能对您有所帮助的两个提示:

  1. value注释中使用@RequestMapping属性。完整URI不是与此value属性的值连接的webapp的上下文路径。
  2. 使用org.springframework.web.servlet.view.tiles3.TilesViewResolver代替org.springframework.web.servlet.view.UrlBasedViewResolver