[Struts]"Cannot find bean in any scope"之一解

简介: 问题描述 今天在开发中遇到一奇怪问题,有一个action,在该action里使用request.setAttribute()方法将一个List类型对象放在request中,然后forward到一个jsp文件,该文件的主要内容是使用<logic:iterate>标签将这个List对象中的条目列表显示。

问题描述

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

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

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

public ActionForward execute( 
   ActionMapping mapping, 
   ActionForm form, 
   HttpServletRequest request, 
   HttpServletResponse response) 
   throws Exception { 

   HibernateDAO dao 
=  HibernateDAO.getInstance(getServlet().getServletContext()); 
   List sfzxjbxxs 
=  dao.find( " from  "   +  SfzxJbxx.class.getName()); 
   SfzxJbxx tmp 
=   new  SfzxJbxx(); 
   tmp.setSfzxid(
" id " ); 
   tmp.setXxdm(
" pku " ); 
   sfzxjbxxs.add(tmp); 
   request.setAttribute(
" sfzxjbxxs " , sfzxjbxxs); 
   
return  mapping.findForward( " success " ); 


listsfzxjbxx.jsp内容如下:

<% @ page contentType="text/html;charset=UTF-8" language="java"  %>  
<% @ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>  
<% @ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>  
< head >  
      
< title > SfzxJbxxList </ title >  
</ head >  
< body >  
< logic:iterate   name ="sfzxjbxxs"  id ="sfzxjbxx" >  
  
< tr >  
    
< td  align ="left" >  
      
< bean:write  name ="sfzxjbxx"  property ="sfzxId"  filter ="true" />  
    
</ td >  
    
< td  align ="left" >  
      
< bean:write  name ="sfzxjbxx"  property ="xxdm"  filter ="true" />  
    
</ td >  
    
< td >  
    
</ td >  
  
</ tr >  
</ logic:iterate >  
< body >  
</ html >  

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

< action-mappings >  
    
< action 
        
attribute ="Form"  
        input
="/form/sfzxjbxx.jsp"  
        name
="sfzxJbxxForm"  
        path
="/saveSfzxJbxx"  
       type
="edu.pku.cc.sfzx.xxgl.action.SaveSfzxJbxxAction"   />  
    
< action     path ="/listsfzxjbxx"  type ="edu.pku.cc.sfzx.xxgl.action.ListSfzxJbxxAction" >  
       
< forward  name ="success"               path ="/form/listsfzxjbxx.jsp" />  
   
</ action >  
         
</ action-mappings >  

问题解决

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

< %@ taglib  uri ="/WEB-INF/struts-logic.tld"  prefix ="logic" % >  

一切OK!

本文转自博客园八进制的博客,原文链接:[Struts]"Cannot find bean in any scope"之一解,如需转载请自行联系原博主。

相关文章
|
Java 数据库连接 mybatis
【Spring常见错误】No qualifying bean of type
📋📋 精彩摘要:MyBatis 核心配置文件(xxxConfig.xml),该文件配置了MyBatis的一些全局信息,,包含数据库连接信息和MyBatis运行时所需的各种特性,以及设置和响应MyBatis行为的一些属性。本文将深入浅出的介绍MyBatis核心配置文件中常用的标签配置。
5410 0
|
5月前
|
Java 数据库连接 Maven
Could not autowire. No beans of ‘ArticleMapper‘ type found. 要添加Mybatis的依赖
Could not autowire. No beans of ‘ArticleMapper‘ type found. 要添加Mybatis的依赖
|
7月前
No qualifying bean of type [com.XX.mapper.SysNameMapper ] found for dependency
No qualifying bean of type [com.XX.mapper.SysNameMapper ] found for dependency
95 0
记一个SpringBoot中属性注入失败的问题Consider defining a bean of type &#39;&#39;&#39; in your configuration...
记一个SpringBoot中属性注入失败的问题Consider defining a bean of type &#39;&#39;&#39; in your configuration...
299 0
|
Java
springboot3 解决:Could not autowire. No beans of ‘JavaMailSender‘ type found
因为 spring-boot-starter-mail 默认使用某些包发生了变化,在 2.2.xx 版本前后不一,解决对应bug
489 0
|
Java 测试技术 Spring
Configuration problem: Failed to import bean definitions from URL location classpath:spring-mvc.xml
Configuration problem: Failed to import bean definitions from URL location classpath:spring-mvc.xml
859 0
idea springboot无法自动装配Could not autowire. No beans of ‘Xxx‘ type found.
idea springboot无法自动装配Could not autowire. No beans of ‘Xxx‘ type found.
idea springboot无法自动装配Could not autowire. No beans of ‘Xxx‘ type found.
记一个SpringBoot中属性注入失败的问题Consider defining a bean of type ''' in your configuration...
记一个SpringBoot中属性注入失败的问题Consider defining a bean of type ''' in your configuration...
219 0
|
设计模式 XML Java
SPRING02_核心注解、Bean、primary、DependsOn、Lazy、Scope、ComponentScan、详解Import、Lookup注解(一)
SPRING02_核心注解、Bean、primary、DependsOn、Lazy、Scope、ComponentScan、详解Import、Lookup注解(一)
182 0
SPRING02_核心注解、Bean、primary、DependsOn、Lazy、Scope、ComponentScan、详解Import、Lookup注解(一)
|
容器
SPRING02_核心注解、Bean、primary、DependsOn、Lazy、Scope、ComponentScan、详解Import、Lookup注解(三)
SPRING02_核心注解、Bean、primary、DependsOn、Lazy、Scope、ComponentScan、详解Import、Lookup注解(三)
133 0
SPRING02_核心注解、Bean、primary、DependsOn、Lazy、Scope、ComponentScan、详解Import、Lookup注解(三)