
struts2.0,在jsp中迭代显示list问题
我的action的代码:privateStringusername;privateStringpassword;privateList<Book>contentList;...
我的action的代码:
private String username;
private String password;
private List<Book> contentList ;
//get和set方法就不打出来了,在myeclipse中自动生成的
public String execute() throws Exception {
DB_User du=new DB_User();
DB_Book db=new DB_Book();
User us=du.get(getUsername(), getPassword());
if(us!=null)
{
contentList=db.listgoods();
for(int i=0;i<contentList.size();i++)
{
Book user = (Book)contentList.get(i);
System.out.print(user.getBookname()+"\t");
System.out.print(user.getAuthor()+"\t");
}
return SUCCESS;
} else {
return ERROR;
}
}
jsp中代码:
<s:iterator value="contentList" id="book"></s:iterator>
<s:property value="book.bookname"/>
成功跳转到jsp,但里面什么也没输出
在控制台里list的值都输出出来了,证明list不是空的
就是jsp中显示不出来,struts.xml中的result type也不是redirect,不知道哪里出错了,大侠帮帮忙啊!!能否留个QQ解答下
抱歉jsp中代码:(上面的写错了)
<s:iterator value="contentList" id="book">
<s:property value="book.bookname"/>
</s:iterator> 展开
private String username;
private String password;
private List<Book> contentList ;
//get和set方法就不打出来了,在myeclipse中自动生成的
public String execute() throws Exception {
DB_User du=new DB_User();
DB_Book db=new DB_Book();
User us=du.get(getUsername(), getPassword());
if(us!=null)
{
contentList=db.listgoods();
for(int i=0;i<contentList.size();i++)
{
Book user = (Book)contentList.get(i);
System.out.print(user.getBookname()+"\t");
System.out.print(user.getAuthor()+"\t");
}
return SUCCESS;
} else {
return ERROR;
}
}
jsp中代码:
<s:iterator value="contentList" id="book"></s:iterator>
<s:property value="book.bookname"/>
成功跳转到jsp,但里面什么也没输出
在控制台里list的值都输出出来了,证明list不是空的
就是jsp中显示不出来,struts.xml中的result type也不是redirect,不知道哪里出错了,大侠帮帮忙啊!!能否留个QQ解答下
抱歉jsp中代码:(上面的写错了)
<s:iterator value="contentList" id="book">
<s:property value="book.bookname"/>
</s:iterator> 展开
6个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询