struts2中用<s:iterator value="/">把数据库记录显示在表格中,总是重复显示记录最后一条。。
publicclassstuinfoextendsActionSupport{/****/privatestaticfinallongserialVersionUID=1...
public class stuinfo extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
private String id;
private String name;
private String classes;
private String score;
public List<String> list;
public List<String> getList() {
return list;
}
public void setList(List<String> list) {
this.list = list;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getClasses() {
return classes;
}
public void setClasses(String classes) {
this.classes = classes;
}
public String getScore() {
return score;
}
public void setScore(String score) {
this.score = score;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
public String execute(){
try{
list=new ArrayList();
Connection con = new connection().getConnection() ;
Statement stmt=con.createStatement();
String sql = "select id,name,classes,score from stuinfo";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
list.add(id=rs.getString("id"));
list.add(name=rs.getString("name"));
list.add(classes=rs.getString("classes"));
list.add(score=rs.getString("score"));
}
return SUCCESS;
}catch(Exception e){ }
return SUCCESS;
}
}
<s:form action="" method="post">
<table width="442" border="1" cellpadding="1" cellspacing="0" style="border-style: inherit" >
<tr>
<td>id</td><td>姓名</td><td>班级</td><td>成绩</td><td>修改</td><td>删除</td><td>添加</td>
</tr>
<s:iterator value="list">
<tr>
<td><s:property value="id"/></td>
<td><s:property value="name"/></td>
<td><s:property value="classes"/></td>
<td><s:property value="score"/></td>
<td>修改信息</td>
<td>删除信息</td>
<td>添加信息</td>
</tr>
</s:iterator> 展开
/**
*
*/
private static final long serialVersionUID = 1L;
private String id;
private String name;
private String classes;
private String score;
public List<String> list;
public List<String> getList() {
return list;
}
public void setList(List<String> list) {
this.list = list;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getClasses() {
return classes;
}
public void setClasses(String classes) {
this.classes = classes;
}
public String getScore() {
return score;
}
public void setScore(String score) {
this.score = score;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
public String execute(){
try{
list=new ArrayList();
Connection con = new connection().getConnection() ;
Statement stmt=con.createStatement();
String sql = "select id,name,classes,score from stuinfo";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
list.add(id=rs.getString("id"));
list.add(name=rs.getString("name"));
list.add(classes=rs.getString("classes"));
list.add(score=rs.getString("score"));
}
return SUCCESS;
}catch(Exception e){ }
return SUCCESS;
}
}
<s:form action="" method="post">
<table width="442" border="1" cellpadding="1" cellspacing="0" style="border-style: inherit" >
<tr>
<td>id</td><td>姓名</td><td>班级</td><td>成绩</td><td>修改</td><td>删除</td><td>添加</td>
</tr>
<s:iterator value="list">
<tr>
<td><s:property value="id"/></td>
<td><s:property value="name"/></td>
<td><s:property value="classes"/></td>
<td><s:property value="score"/></td>
<td>修改信息</td>
<td>删除信息</td>
<td>添加信息</td>
</tr>
</s:iterator> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询