struts查询数据库显示的问题!!!!在线等………………

IT成长营-小刀神 IT成长营-小刀神 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我查询数据库数据显示时,只能显示最后一条记录N次(N为查询结果的行数)!!!!看了半天还是不能解决!!



action:
public class NewsAction extends Action {
public ActionForward perform(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
/**@todo: complete the business logic here, this is just a skeleton.*/
newsActionForm newsActionForm = (newsActionForm) actionForm;
Statement stmt;
ResultSetMetaData rm;
ArrayList objAry=new ArrayList();
DBConnect dbconn=new DBConnect();
Vector v=new Vector();
try {
stmt=dbconn.getStatement();
ResultSet rs=stmt.executeQuery("select * from news");
while(rs.next()){
newsActionForm.setTitle(rs.getString(1));
v.addElement(newsActionForm);
objAry.add(newsActionForm);
}
dbconn.getConnection().commit();
}
catch (SQLException ex) {
ex.printStackTrace();
}
System.out.println(objAry.size());
httpServletRequest.setAttribute("newsinfo",objAry.toArray());
return actionMapping.findForward("success");
}
}



JSP页面:

<logic:iterate id="newsActionForm" name="newsinfo" indexId="title" offset="1">
<tr nowrap><bean:write name="newsActionForm" property="title" /></tr>
</logic:iterate>
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
IT成长营-小刀神
Web 开发 81,108 成员 341,721 内容