我正在尝试显示结果集jsp,但是在结果集中的最后一条记录再次显示。由动作类获取。但我认为逻辑:ierate不工作。我无法解决这个问题。我发送的是我的整个代码。请帮帮我,我该如何解决我的问题?
public class ReportsAction extends org.apache.struts.action.Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
String target = null;
ReportActionForm f=(ReportActionForm) form;
String loanAmount=f.getloanAmount();
String Status=f.getstatus();
String City=f.getCity();
String LoanFor=f.getLoanType();
String BankName=f.getBankName();
String Team=f.getTeam();
String RegDate=f.getRegDate();
String RegDate2=f.getRegDate2();
Logger l1=Logger.getLogger("my");
l1.info("city : "+City);
Class.forName("com.mysql.jdbc.Driver");
Connection con=(Connection) DriverManager.getConnection("jdbc:mysql://SERVER:3306/dsa","dexpertuser","Dspl_2014");
ArrayList<ReportBean> list=new ArrayList<ReportBean>();
ReportBean rb=new ReportBean();
//------------------------------------------------------------------------------------------------------------
l1.info("city : "+City);
String cmd="select * from DSA.lead where City='"+City+"' or Status='"+Status+"' or LoanFor='"+LoanFor+"' or BankName='"+BankName+"' or Team='"+Team+"'";
Statement st=(Statement) con.createStatement();
ResultSet rs=st.executeQuery(cmd);
while(rs.next())
{
rb.setUserName(rs.getString("UserName"));
rb.setCity(rs.getString("City"));
rb.setLoanAmount(rs.getString("LoanAmount"));
rb.setStatus(rs.getString("Status"));
rb.setBankName(rs.getString("BankName"));
l1.info("city IS: "+rs.getString("UserName"));
list.add(rb);
}
if(list.isEmpty())
{
target="Yes";
}
else{
target="success";
request.setAttribute("list1", list);
}
return mapping.findForward(target);
}
}
Otput jsp page:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<table border="1">
<tr><th>User Name :</th><th>City</th><th>Loan Amount</th><th>Status</th><th> Bank Name</th></tr>
<logic:iterate name="list1" id="A" >
<tr><td><bean:write name="A" property="userName" /></td>
<td><bean:write name="A" property="city" /></td>
<td><bean:write name="A" property="loanAmount" /></td>
<td><bean:write name="A" property="status" /></td>
<td><bean:write name="A" property="bankName" /></td></tr>
</tr>
</logic:iterate>
</table>
</body>
答案 0 :(得分:0)
使用结果集后,您不是 清理 。这可能会导致问题。
while(rs.next())
{
rb.setUserName(rs.getString("UserName"));
rb.setCity(rs.getString("City"));
rb.setLoanAmount(rs.getString("LoanAmount"));
rb.setStatus(rs.getString("Status"));
rb.setBankName(rs.getString("BankName"));
l1.info("city IS: "+rs.getString("UserName"));
list.add(rb);
}
//Clean-up environment
rs.close();
st.close();
con.close();