瓷砖通配符和Spring mvc

时间:2014-07-31 11:12:47

标签: java spring-mvc tiles apache-tiles tiles-3

我正在使用带有野猫的spring 3 mvc Tiles,我确实得到了参数的值。 我定义了我的观点:

<definition name="recurso/*/*" extends="genericTemplate">
    <put-attribute name="titulo" value="Recurso" />
    <put-attribute name="body">
        <definition extends="dosColumnasTemplate" >
            <put-attribute name="izquierda" value="/WEB-INF/views/recursos/detalle/{1}.jsp" />
            <put-attribute name="derecha" value="/WEB-INF/views/recursos/detalle/{2}.jsp" />
        </definition>
    </put-attribute>
</definition>

该方法调用处理程序:

@RequestMapping(value="/recurso/{id}", method = RequestMethod.GET)
public String printRecurso(@PathVariable(value = "id") Long id, ModelMap model)
{
  model.addAttribute("active", "recursos");
  return "recurso/campos/grupos";
}

我正在使用TilesView:

<!-- Tiles View Url Based Resolver -->
<bean id="tilesViewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
       <property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView" />
</bean>

结果是以下错误: Servlet jsp的El Servlet.service()引发了异常 javax.servlet.ServletException:JSP文件“/ WEB-INF / views / recursos / detalle / jsp {1}。”找不到

javax.servlet.ServletException:JSP文件“/ WEB-INF / views / recursos / detalle / jsp {2}。”找不到

2 个答案:

答案 0 :(得分:0)

似乎是link

中提到的一些罐子问题
  • tiles-api 3.0.1 jar
  • tiles-core 3.0.1 jar
  • tiles-jsp 3.0.1 jar
  • tiles-request-api 1.0.1 jar
  • commons-digester 2.0 jar
  • commons-beanutils 1.8.0 jar

答案 1 :(得分:0)

我的pom.xml

<modelVersion>4.0.0</modelVersion>
<groupId>es.omb</groupId>
<artifactId>recursos</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>recursos Maven Webapp</name>
<url>http://maven.apache.org</url>

<properties>
    <spring.version>3.2.10.RELEASE</spring.version>
    <tiles.version>3.0.4</tiles.version>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-extras</artifactId>
        <version>${tiles.version}</version>
    </dependency>   

    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

</dependencies>
<build>
    <finalName>recursos</finalName>
</build>

我的调度员:

<context:component-scan base-package="es.omb.recursos.controllers" />

<!-- Spring Internal View Resolver -->
<!-- 
<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/WEB-INF/views/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>
-->

<!-- Tiles Configuration --> 
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/tiles/templates.xml</value>
            <value>/WEB-INF/tiles/recursos.xml</value>
            <value>/WEB-INF/tiles/duplicados.xml</value>
            <value>/WEB-INF/tiles/tipoloxias.xml</value>
            <value>/WEB-INF/tiles/campos.xml</value>
        </list>
    </property>
</bean>

<!-- Tiles View Url Based Resolver -->
<bean id="tilesViewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
       <property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView" />
</bean>


<!-- Recursos estáticos css y js -->
<mvc:annotation-driven />
<mvc:resources mapping="/assets/**" location="/assets/" />

我的图块配置templates.xml:

<!-- Plantilla genérica con el menú, body y footer -->
<definition name="genericTemplate" template="/WEB-INF/views/templates/template.jsp">
    <put-attribute name="menu" value="/WEB-INF/views/templates/menus/superior.jsp" />
    <put-attribute name="footer" value="/WEB-INF/views/templates/footer.jsp" />
</definition>

<!-- Plantilla genérica del body de una columna -->
<definition name="unaColumnaTemplate" template="/WEB-INF/views/templates/body/una-columna.jsp">
</definition>

<!-- Plantilla genérica del body de dos columnas -->
<definition name="dosColumnasTemplate" template="/WEB-INF/views/templates/body/dos-columnas.jsp">
</definition>

<!-- Plantilla genérica del body de tres columnas -->
<definition name="tresColumnasTemplate" template="/WEB-INF/views/templates/body/tres-columnas.jsp">
</definition>   

<definition name="recurso/*/*" extends="genericTemplate">
    <put-attribute name="titulo" value="Recurso" />
    <put-attribute name="body">
        <definition extends="dosColumnasTemplate" >
            <put-attribute name="izquierda" value="/WEB-INF/views/recursos/detalle/{1}.jsp" />
            <put-attribute name="derecha" value="/WEB-INF/views/recursos/detalle/{2}.jsp" />
        </definition>
    </put-attribute>
</definition>