用java写了一个发帖的小程序,可以发帖子,但是帖子在jsp页面读不出来!郁闷,求解...
贴出一部分我的代码:
[color=red]jsp页面代码:[/color]用了两种标签都取不出来!
/s:debug${text}
${v.name} | ${v.title} | ${v.content} |
[color=red]ForumAction一部分代码:([/color]action可以取到已发布的帖子)
public String find() throws Exception {
BbsDao bbsdao = new BbsDao();
bbs = bbsdao.findAllBbs();
for(Bbs b : bbs){
System.out.println(b.getContent());
}
return "find";
}
[color=red]strutrs.xml代码:[/color]
/bbs_list.jsp
/bbs_list.jsp
就是郁闷action里面已经取到帖子,就是传不到jsp页面遍历???那里出错了呢?积分太少,只有5分了...
必须通过action去调jsp,不然jsp肯定不知道值存哪里的
//发表文章
public String insert() throws Exception {
BbsDao bbsdao = new BbsDao();
//bbsdao.save(name,title,content);
this.find();
text = "文章发表成功";
return "insert";
}
//读取文章
public String find() throws Exception {
BbsDao bbsdao = new BbsDao();
//bbs = bbsdao.findAllBbs();
bbs = new ArrayList<Bbs>();
for(int i=0;i<4;i++){
Bbs a = new Bbs();
a.setId(i+10);
a.setName("good luck"+i);
a.setTitle("thank you " + i + 5);
a.setContent("every one " + i +100);
bbs.add(a);
}
getRequest().setAttribute("bbs", bbs);
return "find";
}
页面标签库引入了没有?
你用的struts2?action中bbs添加了get,set方法没有,没有就添加试试。
换成struts标签,前提是你getset方法都在action里面写了。
[code="java"]
/s:iterator
[/code]
如果没有写getset方法,又不想用struts标签,那就得
[code="java"] ServletActionContext.getRequest().setAttribute("bbs", bbs);
[/code]