Problem description
Today, I encountered a strange problem during development. There is an action in which request is used. the setattribute () method places a list object in the request and forward it to a JSP file. The main content of this file is to use <logic: iterate> label displays the list of entries in this list object. It is the same logic but located in another module (teacher ).CodeThe execution is normal. But the code in this module (xxgl) is simple logic, but always prompts:
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)
After removing the codes between <logic: iterate>, no error is prompted. Therefore, it is suspected that the code in <Bean: Write> has an error. The execute method in the listsfzxjbxxaction. Java file is as follows:
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 " );
}
The content of listsfzxjbxx. jsp is as follows:
<% @ Page contenttype="Text/html; charsets = 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 >
The module configuration file contains the following content:
< 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 >
Problem Solving
After three hours of inspection, it was found that the <logic: iterate> label statement is missing in listsfzxjbxx. jsp. Add the following in front:
< % @ Taglib Uri = "/WEB-INF/struts-logic.tld" Prefix = "Logic" % >
Everything is OK!