struts查询数据库显示的问题!!!!在线等………………
我查询数据库数据显示时,只能显示最后一条记录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>