问题描述

今天在开发中遇到一奇怪问题,有一个action,在该action里使用request.setAttribute()方法将一个List类型对象放在request中,然后forward到一个jsp文件,该文件的主要内容是使用<logic:iterate>标签将这个List对象中的条目列表显示。与它同样逻辑但位于另一模块(teacher)中的代码执行正常。但这个模块(xxgl)中的代码,本来很简单的逻辑,却总是提示:

[Struts]"Cannot find bean in any scope"之一解org.apache.jasper.JasperException: Cannot find bean t in any scope 
[Struts]"Cannot find bean in any scope"之一解at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:
254
[Struts]"Cannot find bean in any scope"之一解at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:
295
[Struts]"Cannot find bean in any scope"之一解at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:
241
[Struts]"Cannot find bean in any scope"之一解at javax.servlet.http.HttpServlet.service(HttpServlet.java:
853
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:
684
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:
432
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:
356
[Struts]"Cannot find bean in any scope"之一解at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:
1069
[Struts]"Cannot find bean in any scope"之一解at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:
455
[Struts]"Cannot find bean in any scope"之一解at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:
279
[Struts]"Cannot find bean in any scope"之一解at org.apache.struts.action.ActionServlet.process(ActionServlet.java:
1482
[Struts]"Cannot find bean in any scope"之一解at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:
507
[Struts]"Cannot find bean in any scope"之一解at javax.servlet.http.HttpServlet.service(HttpServlet.java:
740
[Struts]"Cannot find bean in any scope"之一解at javax.servlet.http.HttpServlet.service(HttpServlet.java:
853
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
247
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
193
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
256
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:
643
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:
480
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:
995
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
191
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:
643
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:
480
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:
995
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:
2417
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
180
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:
643
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:
171
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:
641
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
172
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:
641
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:
480
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:
995
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
174
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:
643
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:
480
[Struts]"Cannot find bean in any scope"之一解at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:
995
[Struts]"Cannot find bean in any scope"之一解at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:
193
[Struts]"Cannot find bean in any scope"之一解at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
781
[Struts]"Cannot find bean in any scope"之一解at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:
549
[Struts]"Cannot find bean in any scope"之一解at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:
589
[Struts]"Cannot find bean in any scope"之一解at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:
666
[Struts]"Cannot find bean in any scope"之一解at java.lang.Thread.run(Unknown Source) 
[Struts]"Cannot find bean in any scope"之一解

将<logic:iterate>之间的代码去掉后就不会提示错误了,所以怀疑是<bean:write>中的代码有错误。相关文件ListSfzxJbxxAction.java中的execute方法如下:

[Struts]"Cannot find bean in any scope"之一解public ActionForward execute( 
[Struts]"Cannot find bean in any scope"之一解   ActionMapping mapping, 
[Struts]"Cannot find bean in any scope"之一解   ActionForm form, 
[Struts]"Cannot find bean in any scope"之一解   HttpServletRequest request, 
[Struts]"Cannot find bean in any scope"之一解   HttpServletResponse response) 
[Struts]"Cannot find bean in any scope"之一解   throws Exception { 
[Struts]"Cannot find bean in any scope"之一解
[Struts]"Cannot find bean in any scope"之一解   HibernateDAO dao 
= HibernateDAO.getInstance(getServlet().getServletContext()); 
[Struts]"Cannot find bean in any scope"之一解   List sfzxjbxxs 
= dao.find("from " + SfzxJbxx.class.getName()); 
[Struts]"Cannot find bean in any scope"之一解   SfzxJbxx tmp 
= new SfzxJbxx(); 
[Struts]"Cannot find bean in any scope"之一解   tmp.setSfzxid(
"id"); 
[Struts]"Cannot find bean in any scope"之一解   tmp.setXxdm(
"pku"); 
[Struts]"Cannot find bean in any scope"之一解   sfzxjbxxs.add(tmp); 
[Struts]"Cannot find bean in any scope"之一解   request.setAttribute(
"sfzxjbxxs", sfzxjbxxs); 
[Struts]"Cannot find bean in any scope"之一解   
return mapping.findForward("success"); 
[Struts]"Cannot find bean in any scope"之一解
[Struts]"Cannot find bean in any scope"之一解

listsfzxjbxx.jsp内容如下:

模块配置文件中相关内容如下:

[Struts]"Cannot find bean in any scope"之一解<action-mappings> 
[Struts]"Cannot find bean in any scope"之一解    
<action 
[Struts]"Cannot find bean in any scope"之一解        
attribute="Form" 
[Struts]"Cannot find bean in any scope"之一解        input
="/form/sfzxjbxx.jsp" 
[Struts]"Cannot find bean in any scope"之一解        name
="sfzxJbxxForm" 
[Struts]"Cannot find bean in any scope"之一解        path
="/saveSfzxJbxx" 
[Struts]"Cannot find bean in any scope"之一解        type
="edu.pku.cc.sfzx.xxgl.action.SaveSfzxJbxxAction" /> 
[Struts]"Cannot find bean in any scope"之一解    
<action    path="/listsfzxjbxx" type="edu.pku.cc.sfzx.xxgl.action.ListSfzxJbxxAction"> 
[Struts]"Cannot find bean in any scope"之一解        
<forward name="success"              path="/form/listsfzxjbxx.jsp"/> 
[Struts]"Cannot find bean in any scope"之一解    
</action> 
[Struts]"Cannot find bean in any scope"之一解          
[Struts]"Cannot find bean in any scope"之一解
</action-mappings> 
[Struts]"Cannot find bean in any scope"之一解

问题解决

经过三个小时的检查,发现是listsfzxjbxx.jsp里缺少<logic:iterate>标签的声明,在前面增加上:

[Struts]"Cannot find bean in any scope"之一解<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%> 

一切OK!

相关文章: