使用的是struts2,在jsp中打算遍历action的list来显示一个列表。在action里面定义了private List的成员变量,并加了get set方法,按理说就可以在jsp中用iterator来遍历,但是实际上并不能。list里面元素的属性全都取不到。
使用el表达式可以逐一取出来。
不用list可以取到值,用list取不到值,使用<s:property value="userlist[1]"/>
则可以访问到list的元素的地址。
怀疑是struts2的标签写错了,语法有误,但网上找来找去都是这么写的,看不出啥问题。
jsp的代码:
<s:iterator value="hotBlogList" id="project" var ="pro" status="st">
<a href="#" class="list-group-item">
<div class="row">
<div class="col-md-12">
<h4 class="article-name"><s:property value="bTitle"/></h4>
<div class="hidden-xs"><!--小屏幕隐藏文章简介-->
<p class="article-des"><s:property value="bBrief"/></p>
</div>
</div>
<div class="inteact-info col-md-9 col-md-offset-3 col-xs-12">
<span>
<i class="fa fa-eye"></i> <s:property value="bViewNum"/>
</span>
<span>
<i class="fa fa-thumbs-o-up"></i> <s:property value="bLikeNum"/>
</span>
<span>
<i class="fa fa-comment"></i> <s:property value="bCommentNum"/>
</span>
</div>
</div>
</a>
</s:iterator>
action的代码;
private static final long serialVersionUID = 1L;
private List<Blog> hotBlogList = null;
private String testtest = "123";
public String execute() throws Exception {
MybatisInit mbInit = new MybatisInit();
testtest = "456";
//获取mapper句柄
BlogMapper bMapper = mbInit.getSession().getMapper(BlogMapper.class);
try {
hotBlogList = bMapper.selectHotBlog();
for(int i = 0; i < hotBlogList.size(); i++){
System.out.println(hotBlogList.get(0).getbTitle());
}
System.out.println(hotBlogList.toString());
return "success";
} catch (Exception e) {
e.printStackTrace();
return "error";
}
finally{
mbInit.getSession().close();
}
}
debug的信息:
struts 过时了