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>
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>
...全文
相关推荐
struts在线投票
**jsp在线投票**:JSP页面通常用来显示投票的选项、用户的投票状态以及投票结果。它们可以包含HTML、CSS、JavaScript以及嵌入的Java代码,用于处理用户交互和数据呈现。5.
struts中文显示问题
Struts框架是一个经典的Java Web开发框架,用于构建MVC(模型-视图-控制器)架构的应用程序。在处理中文字符时,Struts可能会遇到显示乱码的问题,这主要是由于字符编码不一致导致的。
解决struts2的s:checkbox显示难看问题
确保插件与Struts2标签兼容,或者使用Struts2的AJAX支持。7. **编码问题**:有时候,中文字符在页面上显示不正常,可能是由于编码设置不正确。
在线答题系统(java、jsp、hibernate、struts1)
该项目是一个基于Java、JSP、Hibernate和Struts1实现的在线答题系统,包含用户登录、密码修改、题目管理和考试查询等功能。通过Struts配置实现请求分发,利用Hibernate与Or
基于Struts2在线考试系统
基于Struts2的在线考试系统是典型JavaEE应用。它以Struts2为MVC框架,结合MySQL存储数据,用JSP展示页面。具备验证码登录保障安全,支持题目分页显示,可动态调整每页题目数。还涉及


Web 开发
