Apache Tiles:管理CSS和JS资源

时间:2014-02-12 12:23:50

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

我在解决这个问题时遇到了问题。我想在我需要的某些页面上插入某些CSS和JS文件。所以我在tile定义文件中做了类似的事情:

  <definition name="datepickerScripts" template="/WEB-INF/jsp/insertScripts.jsp">
      <put-list-attribute name="scriptsList" cascade="true">
         <add-attribute value="js/jquery-ui.min.js" />
         <add-attribute value="js/setup-datepicker.js" />
      </put-list-attribute>
  </definition>

  <definition name="formValidationScripts" template="/WEB-INF/jsp/insertScripts.jsp">
      <put-list-attribute name="scriptsList" cascade="true">
         <add-attribute value="js/validate.min.js" />
         <add-attribute value="js/formValidationHelpers.js" />
      </put-list-attribute>
  </definition>
  <definition name="addUser" extends="layout">
      <put-attribute name="title" value="users.add" />
      <put-attribute name="content" value="/WEB-INF/jsp/addUser.jsp" />
      <put-attribute name="datepickerScriptBundle" type="definition">
          <definition extends="datepickerScripts" />
      </put-attribute>
  </definition>

这是insertScripts.jsp代码:

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

<spring:url value="/" var="url" />
<tilesx:useAttribute id="list" name="scriptsList" classname="java.util.List" />
<c:forEach var="item" items="${list}">
    <script type="text/javascript" src="${url}${item}"></script>
</c:forEach>

所以我在我的baseLayout页面中调用它,这是addUser页面的父页面:

<tiles:insertAttribute name="datepickerBundleScript" ignore="true" />

问题是它抛出以下异常:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.apache.tiles.request.render.CannotRenderException: ServletException including path '/WEB-INF/jsp/baseLayout.jsp'.
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:965)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:717)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1644)
    at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:164)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1615)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1632)
    at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:180)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1624)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:550)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:568)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1110)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:479)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1044)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:199)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:459)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:281)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:232)
    at org.eclipse.jetty.io.AbstractConnection$1.run(AbstractConnection.java:505)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)
    at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.tiles.request.render.CannotRenderException: ServletException including path '/WEB-INF/jsp/baseLayout.jsp'.
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:399)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:238)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:221)
    at org.apache.tiles.renderer.DefinitionRenderer.render(DefinitionRenderer.java:59)
    at org.springframework.web.servlet.view.tiles3.TilesView.renderMergedOutputModel(TilesView.java:145)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:263)
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208)
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
    ... 33 more
Caused by: java.io.IOException: ServletException including path '/WEB-INF/jsp/baseLayout.jsp'.
    at org.apache.tiles.request.servlet.ServletUtil.wrapServletException(ServletUtil.java:61)
    at org.apache.tiles.request.servlet.ServletRequest.forward(ServletRequest.java:267)
    at org.apache.tiles.request.servlet.ServletRequest.doForward(ServletRequest.java:228)
    at org.apache.tiles.request.AbstractClientRequest.dispatch(AbstractClientRequest.java:57)
    at org.apache.tiles.request.render.DispatchRenderer.render(DispatchRenderer.java:47)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:259)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:397)
    ... 43 more
Caused by: org.apache.tiles.template.NoSuchAttributeException: Attribute 'null' not found.
    at org.apache.tiles.template.DefaultAttributeResolver.computeAttribute(DefaultAttributeResolver.java:50)
    at org.apache.tiles.template.InsertAttributeModel.resolveAttribute(InsertAttributeModel.java:165)
    at org.apache.tiles.template.InsertAttributeModel.execute(InsertAttributeModel.java:121)
    at org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:299)
    at org.apache.jsp.WEB_002dINF.jsp.baseLayout_jsp._jspx_meth_tiles_insertAttribute_4(baseLayout_jsp.java:317)
    at org.apache.jsp.WEB_002dINF.jsp.baseLayout_jsp._jspService(baseLayout_jsp.java:142)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:717)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:552)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:586)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1110)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:479)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1044)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:261)
    at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:101)
    at org.apache.tiles.request.servlet.ServletRequest.forward(ServletRequest.java:265)
    ... 48 more

1 个答案:

答案 0 :(得分:3)

我很尴尬。我的代码没有任何问题。我刚刚在<tiles:insertAttribute name="datepickerBundleScript" ignore="true" />之后删除了注释代码并且它有效。所以我认为Tiles不会忽略JSP注释?