我在action bean里调用了一个自己创建的service实体类,然后在该类中得到一个arraylist,并用request.setAttribute("testresults",resultList)把它放到request中.
在jsp页面上可以用<%=request.getAttribute("testresults")%>显示出
[cn.com.DAOC.basedata.test.TestService@1e4e3e4, cn.com.DAOC.basedata.test.TestService@2dce4e, cn.com.DAOC.basedata.test.TestService@14382c6]
使用<bean:size id= "size" name= "testresults" scope= "request"/>也可以得到结果集是3条数据
在<logic:iterate id= "result" name= "testresults" scope= "request">也可以知道是3行数据
但是如果使用<bean:write name= "TestService" property= "tname" scope= "request"/>读取数据,就报出错误javax.servlet.ServletException: Cannot find bean TestService in scope request
请问一下该如何解决

解决方案 »

  1.   

    <bean:write name= "TestService" property= "tname" scope= "request"/>
    这句话的意思是输出一个叫TestService的bean里面的tname的属性的值,问题是你有把TestService这个对象放在request里面么?
      

  2.   

    不好意思,请问怎么把TestService这个对象放在request里面,
      

  3.   

    你如果想循环打印数据的话应该:
    <logic:iterate id= "result" name= "testresults" scope= "request">
        <bean:write name= "result" property= "tname" >
    </logic:iterate>
      

  4.   

    哦,现在正确了,是不是logic:iterate的id需要和bean:write的name一致??还有我想问一下bean:write的scope如果为空,则默认为从什么地方读数据??
      

  5.   

    回楼上,如果是要循环输出的话,那么bean:write 的name应该是要与logic:iterate的id一致。
    如果scope为空的话,默认是从request里面取的
      

  6.   

    但是我如果在<bean:write name= "result" property= "tname"/ >里加了 scope= "request",就又报错误了javax.servlet.ServletException: Cannot find bean result in scope request
      

  7.   


    但是我如果在<bean:write name= "result" property= "tname"/ >里加了 scope= "request",就又报错误了
    =============================================================
    现在是pageContext了,当然是不在request了