日期:2014-05-20  浏览次数:20655 次

jsp中为何获得不了action中返回的list?急求!!!
action中有
private List<Post> posts;
和它的getter,setter.
jsp页面中如下:
HTML code

<table width="60%">
    <tr>
        
        <td width="40%">标题</td>
        <td width="20%">发帖人</td>
        <td width="20%">回复数</td>
        <td width="20%">最后更新</td>
    </tr>
    <s:iterator value="posts" id="post">
        <tr>
          <td><s:property value="#post.p_title" /></td>
        <td><s:property value="#post.postUser.username" /></td>
        <td><s:property value="#post.replyNum" /></td>
        <td><s:property value="#post.lastUpdateUser.username" /></td>
        </tr>
    </s:iterator>
</table>



但是获取不到list的值,后台输出是有值的。
我的jsp页面是不是写的有问题啊?
求高手帮忙看看啊!应该怎么写啊!

------解决方案--------------------
问题出在你的action方法的返回值;
返回值为 void JSP页可以加载 不影响,action方法也会运行,后台会打印属性,这也不影响,唯一影响的是你的action方法执行以后,其属性并没有传回到你加载的页面,你的JSP页之所以加载出来了,是通过其他方法加载的,而不是通过action的返回值跳转过来的;
总结就是:JSP加载了 action运行了 但是你运行的结果没有传回到JSP页。 说这么多应该明白了吧:
解决方案就是 在action中写一个返回值 return "success"; 然后struts.xml中配个result
<result name="success">这里填写你的能够看到结果的JSP页<result/>
------解决方案--------------------
public void listpost(){

 
}
晕。。。都没跳转,你怎么让这方法跳到你的jsp页面?
public String listpost(){
return "succese";
}