首页
JAVA笔记
数据库笔记
混乱记忆
小站记
您现在的位置
struts2循环include 问题
简介: struts2在循环include的时候一直报错,折腾了几天终于找到办法了。希望能够对同样苦命的人有所帮助,总的来讲应该是发现一个strtus的bug。

struts2在循环include的时候一直报错,折腾了几天终于找到办法了,希望能够对同样苦命的人有所帮助,总的来讲应该是发现一个strtus2的bug。

 

方案一

因为页面URL是数据库取出来的所有需要循环include来输出。

<s:iterator id="block" value="#request.pageTemplet.pageBlocks" status="index">
   <s:include value="${block.frameWindow.url}"></s:include>

 </s:iterator>

上面的代码除了后台报错以外前端页面一片空白。

错误信息如下:(为了项目安全xxx代表的是路径或者文件夹)

[DEBUG]-aaa-[org.apache.jasper.compiler.Compiler] 2013-07-21 00:44:17,176 Compiler: outdated: E:\apache-tomcat-5.5.20\work\Catalina\localhost\xxx_jsp.class 1374338365181
[DEBUG]-aaa-[org.apache.struts2.dispatcher.ng.PrepareOperations] 2013-07-21 00:44:17,192 skipping cleanup counter=2
[ERROR]-aaa-[org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/xxx].[jsp]] 2013-07-21 00:44:17,192 Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /xxx.jsp(56,3) According to TLD or attribute directive in tag file, attribute value does not accept any expressions
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
at org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:955)
at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:710)
at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1441)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:730)
at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1441)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)

 

方案二

<s:iterator id="block" value="#request.pageTemplet.pageBlocks" status="index">

 <jsp:include flush="false" page="${block.frameWindow.url}"></jsp:include>

</s:iterator>

上面的代码除了后台出错外只include了一个页面。

错误信息如下:(为了项目安全xxx代表的是路径或者文件夹)

[DEBUG]-aaa-[org.apache.struts2.dispatcher.ng.PrepareOperations] 2013-07-21 00:57:18,411 skipping cleanup counter=4
[DEBUG]-aaa-[org.apache.struts2.dispatcher.ng.PrepareOperations] 2013-07-21 00:57:18,411 skipping cleanup counter=3
[DEBUG]-aaa-[org.apache.catalina.core.ApplicationDispatcher] 2013-07-21 00:57:18,411 servletPath=/manager/pageBlockManager/pages/, pathInfo=null, queryString=null, name=null
[DEBUG]-aaa-[org.apache.catalina.core.ApplicationDispatcher] 2013-07-21 00:57:18,411  Path Based Include
[WARN]-aaa-[org.apache.struts2.dispatcher.Dispatcher] 2013-07-21 00:57:18,411 Could not find action or result
There is no Action mapped for action name xxx. - [unknown location]
 at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189)
 at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
 at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
 at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
 at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
 at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
 at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
 at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
 at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:574)
 at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:499)
 at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)

 

 

方案三(正在使用的方案)

经过测试使用下面代码正确解决问题。

<c:forEach items="${request.pageTemplet.pageBlocks}" var="block">
   <jsp:include flush="false" page="${block.frameWindow.url}"></jsp:include>
 </c:forEach>

 

理论上应该可以使用<s:action>表情解决,但是由于参数问题不好解决,我就没有直接测试了,有兴趣测试过的朋友请给我邮箱(admin@xiaoyunduo.org)留言,或者回复我。