Apache Tiles CannotRenderExcption

时间:2016-04-18 16:51:33

标签: java spring spring-mvc apache-tiles

我正在尝试将Tiles添加到我的Web应用程序中,但是当我运行应用程序时遇到了一个CannotRenderException

  

请求处理失败;嵌套异常是   org.apache.tiles.request.render.CannotRenderException:   ServletException包括路径   ' /WEB-INF/tiles/templates/baseLayout.jsp'

这是实际的例外:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.apache.tiles.request.render.CannotRenderException: ServletException including path '/WEB-INF/tiles/templates/baseLayout.jsp'.
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)

我的tile-definition.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!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="baseLayout" template="/WEB-INF/tiles/templates/baseLayout.jsp">
        <put-attribute name="title" value="Sample Title" />
        <put-attribute name="heading" value="" />
        <put-attribute name="tagline" value="" />
        <put-attribute name="navigation" value="/WEB-INF/tiles/templates/navigation.jsp" />
        <put-attribute name="content" value="" />
        <put-attribute name="footer" value="/WEB-INF/tiles/templates/footer.jsp" />
    </definition>

    <definition name="home" extends="baseLayout">
        <put-attribute name="title" value="Products" />
        <put-attribute name="heading" value="Products" />
        <put-attribute name="tagline" value="Available Products" />
        <put-attribute name="content" value="/WEB-INF/views/products.jsp" />
    </definition>

    <definition name="products" extends="baseLayout">
        <put-attribute name="title" value="Products" />
        <put-attribute name="heading" value="Products" />
        <put-attribute name="tagline" value="Available Products" />
        <put-attribute name="content" value="/WEB-INF/views/products.jsp" />
    </definition>

    <definition name="product" extends="baseLayout">
        <put-attribute name="title" value="Product" />
        <put-attribute name="heading" value="Products" />
        <put-attribute name="tagline" value="Product" />
        <put-attribute name="content" value="/WEB-INF/views/product.jsp" />
    </definition>

    <definition name="addProduct" extends="baseLayout">
        <put-attribute name="title" value="Products" />
        <put-attribute name="heading" value="Products" />
        <put-attribute name="tagline" value="Product" />
        <put-attribute name="content" value="/WEB-INF/views/addProduct.jsp" />
    </definition>

    <definition name="login" extends="baseLayout">
        <put-attribute name="title" value="Login" />
        <put-attribute name="heading" value="Login" />
        <put-attribute name="tagline" value="Enter your Credentials" />
        <put-attribute name="content" value="/WEB-INF/views/login.jsp" />
    </definition>

    <definition name="cart" extends="baseLayout">
        <put-attribute name="title" value="Shpping Cart" />
        <put-attribute name="heading" value="Cart" />
        <put-attribute name="tagline" value="your shopping cart" />
        <put-attribute name="content" value="/WEB-INF/views/cart.jsp" />
    </definition>

    <definition name="collectCustomerInfo" extends="baseLayout">
        <put-attribute name="title" value="Customer Details" />
        <put-attribute name="heading" value="Customer Details" />
        <put-attribute name="content" value="/WEB-INF/flows/checkout/collectCustomerInfo.jsp" />
    </definition>

    <definition name="collectShippingDetail" extends="baseLayout">
        <put-attribute name="title" value="Shipping Details" />
        <put-attribute name="heading" value="Shipping Details" />
        <put-attribute name="content" value="/WEB-INF/flows/checkout/collectShippingDetail.jsp" />
    </definition>

    <definition name="orderConfirmation" extends="baseLayout">
        <put-attribute name="title" value="Order Confirmation" />
        <put-attribute name="heading" value="Order Confirmation" />
        <put-attribute name="content" value="/WEB-INF/flows/checkout/orderConfirmation.jsp" />
    </definition>

    <definition name="InvalidCartWarning" extends="baseLayout">
        <put-attribute name="title" value="Invalid Cart" />
        <put-attribute name="heading" value="Invalid Cart" />
        <put-attribute name="content" value="/WEB-INF/flows/checkout/InvalidCartWarning.jsp" />
    </definition>

    <definition name="thankCustomer" extends="baseLayout">
        <put-attribute name="title" value="Thank you" />
        <put-attribute name="heading" value="Thank you" />
        <put-attribute name="content" value="/WEB-INF/flows/checkout/thankCustomer.jsp" />
    </definition>

</tiles-definitions>

我的baseLayout.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title><tiles:insertAttribute name="title" /></title>

        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">

<link href="http://getbootstrap.com/examples/jumbotron/jumbotron.css"   rel="stylesheet">

</head>

<body>

    <div class="container">
        <div class="header">
            <ul class="nav nav-pills pull-right">
                <tiles:insertAttribute name="navigation" />
            </ul>
            <h3 class="text-muted">Trading Cards</h3>
        </div>

        <div class="jumbotron">
            <h1>
                <tiles:insertAttribute name="heading" />
            </h1>
            <p>
                <tiles:insertAttribute name="tagline" />
            </p>
        </div>

        <div class="row">
            <tiles:insertAttribute name="content" />
        </div>

        <div class="footer">
            <tiles:insertAttribute name="footer" />
        </div>

    </div>
</body>
</html>

我还要指出所有<tiles:insertAtrribute name="..." />标签都会给我一个警告。任何有关此的帮助或建议将不胜感激

2 个答案:

答案 0 :(得分:0)

您是否配置了瓷砖视图解析器?如果没有尝试为java配置这样做,就像这样

@Bean
public TilesViewResolver tilesViewResolver() {
    TilesViewResolver tileResolver = new TilesViewResolver();
    tileResolver.setOrder(1);
    return tileResolver;
}

将其顺序设置为1,因此它首先在视图解析器

中解析视图

对于XML,它应该是这样的

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

您还必须在XML中设置订单属性。

答案 1 :(得分:0)

这是从不久前开始的,但我想我会回答以防其他人遇到这种情况。

我相信如果您从定义文件中删除WEB-INF,它将解决您的问题。

 <definition name="baseLayout" template="/tiles/templates/baseLayout.jsp">
    <put-attribute name="title" value="Sample Title" />

Apache Tiles tutorial中,没有任何定义在/WEB-INF文件夹中查看模板。我认为你的模板试图在/WEB-INF/WEB-INF/tiles/templates/baseLayout.jsp找不到。