Spring NestedServletException: Request processing failed exception is tiles CannotRenderException: ServletException including path

HEAT picture HEAT · Oct 11, 2013 · Viewed 62.1k times · Source

I am new to Spring, I am using SPRING 3.0.4 REST MVC with tiles 2.2.2, My question is very clear, when I tried to submit a request with simpler path's which I have configured in mvc-servlet.xml like /WEB-INF/jsp, it runs successfully, but when I tried to access path /WEB-INF/jsp/XYZ/xyz.jsp or /WEB-INF/jsp/ABC/abc.jsp, I get error, I have used tiles to create layout , I have two different roles for my app, one is user and second is admin, so obviously, I have created two dir under /WEB-INF/JSP/user and /WEB-INF/jsp/admin and put common files under /WEB-INF/jsp, so when I created a view (check tiles config in code) for user, I have used /WEB-INF/jsp/user, when access common files it works fine but when I submit a request to access files under /WEB-INF/jsp/user I got following error

HTTP Status 500 - Request processing failed; nested exception is org.apache.tiles.impl.CannotRenderException: ServletException including path '/WEB-INF/jsp/layout/user/layout.jsp'.

type Exception report

message Request processing failed; nested exception is org.apache.tiles.impl.CannotRenderException: ServletException including path '/WEB-INF/jsp/layout/user/layout.jsp'.

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.apache.tiles.impl.CannotRenderException: ServletException including path '/WEB-INF/jsp/layout/user/layout.jsp'.
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

HERE IS LOG

SEVERE: Servlet.service() for servlet [mvc] in context with path [/docuSaver] threw exception [Request processing failed; nested exception is org.apache.tiles.impl.CannotRenderException: ServletException including path '/WEB-INF/jsp/layout/user/layout.jsp'.] with root cause
org.apache.jasper.JasperException: /WEB-INF/jsp/layout/user/header.jsp (line: 21, column: 20) Attribute attribute invalid for tag insertAttribute according to TLD
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:408)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:237)
at org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1265)
at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:875)
at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1539)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2434)
at org.apache.jasper.compiler.Node$Root.accept(Node.java:475)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
at org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1795)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:217)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
at org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:684)
at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:678)
at org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:103)
at org.apache.tiles.jsp.context.JspTilesRequestContext.dispatch(JspTilesRequestContext.java:96)
at org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
at org.apache.tiles.renderer.impl.ChainedDelegateAttributeRenderer.write(ChainedDelegateAttributeRenderer.java:76)
at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:336)
at org.apache.tiles.template.InsertAttributeModel.renderAttribute(InsertAttributeModel.java:210)
at org.apache.tiles.template.InsertAttributeModel.end(InsertAttributeModel.java:126)
at org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:311)
at org.apache.jsp.WEB_002dINF.jsp.layout.user.layout_jsp._jspx_meth_tiles_005finsertAttribute_005f1(layout_jsp.java:145)
at org.apache.jsp.WEB_002dINF.jsp.layout.user.layout_jsp._jspService(layout_jsp.java:78)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at org.apache.tiles.servlet.context.ServletTilesRequestContext.forward(ServletTilesRequestContext.java:241)
at org.apache.tiles.servlet.context.ServletTilesRequestContext.dispatch(ServletTilesRequestContext.java:222)
at org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:690)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:644)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:627)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:321)
at org.springframework.web.servlet.view.tiles2.TilesView.renderMergedOutputModel(TilesView.java:124)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1031)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:815)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:717)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

Here is MY SPRING CONFIG

<context:component-scan base-package="com.XXXX.common.controller" />
<mvc:annotation-driven />
<mvc:default-servlet-handler/>
<bean
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="order" value="2" />
    <property name="viewClass"> 
        <value>org.springframework.web.servlet.view.tiles2.TilesView </value>
    </property>
</bean>
<bean id="tilesConfigurer"
      class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/**/tiles.xml</value>
        </list>
    </property>
</bean> 
<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="order" value="3" />
    <property name="prefix">
        <value>/WEB-INF/jsp/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>

HERE IS TILES CONFIG

<tiles-definitions>
<definition name="userLayout" template="/WEB-INF/jsp/layout/user/layout.jsp">
    <put-attribute name="title" value="" />
    <put-attribute name="header" value="/WEB-INF/jsp/layout/user/header.jsp" />
    <put-attribute name="menu" value="" />
    <put-attribute name="body" value="" />
    <put-attribute name="footer" value="/WEB-INF/jsp/layout/user/footer.jsp" />
</definition>
 <definition name="userHome" extends="userLayout">
    <put-attribute name="title" value="XXXX" />
    <put-attribute name="menu" value="/WEB-INF/jsp/user/menu.jsp" />
    <put-attribute name="body" value="/WEB-INF/jsp/user/body.jsp" />
</definition>
</tiles-definitions>

Here is my WEB XML CONFIG

<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>/WEB-INF/jsp/layout/user/*</url-pattern>
</servlet-mapping>
 <servlet-mapping>
  <servlet-name>jsp</servlet-name>
  <url-pattern>/WEB-INF/jsp/*</url-pattern>
 </servlet-mapping>
  <servlet-mapping>
  <servlet-name>jsp</servlet-name>
  <url-pattern>/WEB-INF/jsp/user/*</url-pattern>
</servlet-mapping>
 <servlet-mapping>
 <servlet-name>jsp</servlet-name>
 <url-pattern>/WEB-INF/*</url-pattern>
 </servlet-mapping>
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
</servlet>
<servlet>
    <servlet-name>mvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

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

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/mvc-servlet.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

HERE IS MY JSP PAGE

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>

<html>
      <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title><tiles:insertAttribute name="title" ignore="true" /></title>
</head>
<body>
    <table border="1" cellpadding="2" cellspacing="2" align="center">
        <tr>
            <td height="30"><tiles:insertAttribute name="header" />
            </td>
        </tr>
        <tr>
            <td height="250"><tiles:insertAttribute name="menu" /></td>
        </tr>
        <tr>
            <td><tiles:insertAttribute name="body" /></td>
        </tr>
        <tr>
            <td height="30"><tiles:insertAttribute name="footer" />
            </td>
        </tr>
        </table>
    </body>
</html>

So, when I try to use the userLayout, it gives me status 500 exeception, It seems, I can only put my jsp pages under /WEB-INF/jsp directory as it is configured in spring at internalViewResolver, because when I created a layout in tiles with all jsp pages under /WEB-INF/jsp , it runs successfully, but when I created a folder and /WEB-INF/jsp/folderName/jspPAGE.jsp, spring start creating problem and it seems spring framework is fighting for finding out deeper path like /WEB-INF/jsp/folder/... So, can some one tell me how to enable spring to find out more path inside the specified path, Also I have a configuration for JSON and XML in spring config which I have not mentioned for simply reduce the code amount

Answer

ysramkumar picture ysramkumar · Oct 22, 2013

By using the Order property for viewresolvers it can be solved..

In your controller, if the return value is userHome, spring goes to tiles configuration. Otherwise it gives an exception, because, Spring first looks for pages under org.springframework.web.servlet.view.InternalResourceViewResolver in your configuration. If it is not found, it throws an Exception. So define property for both view Resolvers and for tiles resolver gives min value than other resolver.

So, spring first looking in tiles resolver.

for tiles resolver:

 <property name="order" value="0"/>;

for org.springframework.web.servlet.view.InternalResourceViewResolver

 <property name="order" value="1"/>;