1

我是 Spring 新手,我正在使用 SPRING 3.0.4 REST MVC 和瓷砖 2.2.2,我的问题很清楚,当我尝试使用我在 mvc-servlet.xml 中配置的更简单的路径提交请求时,例如 /WEB -INF/jsp,它运行成功,但是当我尝试访问路径/WEB-INF/jsp/XYZ/xyz.jsp 或/WEB-INF/jsp/ABC/abc.jsp 时,我得到错误,我使用了tiles要创建布局,我的应用程序有两个不同的角色,一个是用户,第二个是管理员,所以很明显,我在 /WEB-INF/JSP/user 和 /WEB-INF/jsp/admin 下创建了两个目录并将 common /WEB-INF/jsp下的文件,所以当我为用户创建一个视图(检查代码中的tiles配置)时,我使用了/WEB-INF/jsp/user,当访问公共文件时它工作正常但是当我提交请求时访问 /WEB-INF/jsp/user 下的文件我收到以下错误

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)

这是日志

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)

这是我的春季配置

<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>

这是瓷砖配置

<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>

这是我的 WEB XML 配置

<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>

这是我的 JSP 页面

<%@ 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>

因此,当我尝试使用 userLayout 时,它给了我状态 500 异常,看来,我只能将我的 jsp 页面放在 /WEB-INF/jsp 目录下,因为它是在 spring 在 internalViewResolver 中配置的,因为当我创建布局时在 /WEB-INF/jsp 下所有 jsp 页面的磁贴中,它运行成功,但是当我创建一个文件夹和 /WEB-INF/jsp/folderName/jspPAGE.jsp 时,spring 开始创建问题,似乎 spring 框架正在争取找出像/WEB-INF/jsp/folder/这样的更深的路径所以,有人能告诉我如何让spring在指定的路径中找到更多的路径,另外我在spring config中有一个JSON和XML的配置我没有提到只是为了减少代码量

4

4 回答 4

3

通过使用它的Order属性viewresolvers可以解决..

在您的控制器中,如果返回值为userHome,则 spring 将转到图块配置。否则它会给出一个异常,因为 Spring 首先org.springframework.web.servlet.view.InternalResourceViewResolver在您的配置中查找页面。如果没有找到,它会抛出一个Exception. 因此,为两者定义属性,view Resolvers并且 fortiles resolver给出比其他解析器的最小值。

所以,春天首先在瓷砖解析器中寻找。

对于瓷砖解析器:

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

为了org.springframework.web.servlet.view.InternalResourceViewResolver

 <property name="order" value="1"/>;
于 2013-10-22T06:58:32.233 回答
3

问题在于您的 header.jsp 页面,我认为您在该页面上有一些 tiles 属性。尝试删除它们,它将解决您的问题

于 2014-02-17T11:53:23.473 回答
3

在 header.jsp 中。此行与您的 Tiles 属性有问题,调试它并检查包含在您的 tiles.xml 中的页面

于 2014-02-17T11:57:26.973 回答
2

如何阅读实际的异常:

JasperException: /WEB-INF/jsp/layout/user/header.jsp (line: 21, column: 20) Attribute attribute invalid for tag insertAttribute 根据 TLD

你有<tiles:inserAttribute attribute="...">header.jsp.

于 2013-10-11T14:20:15.243 回答