您好我想在jsp文件中传递我的两个ResultSet。我有两个ResultSet rs和rs1。我已将ResultSet存储在单个数组中。现在我想在jsp文件中打印该数组。所以我可以在网页上显示我的结果。请告诉我应该在jsp文件中编写哪些代码。我应该在jsp文件中导入多少文件..请帮助我。
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con= (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/lportal","root","ubuntu123");
PreparedStatement stmt = (PreparedStatement) con.prepareStatement("SELECT * FROM Testi_Testimonial where subject = ?");
PreparedStatement stmt1 = (PreparedStatement) con.prepareStatement("SELECT * FROM Testi_Testimonial where subject != ?");
stmt.setString(1,search);
stmt.execute();
rs=(ResultSet) stmt.getResultSet();
stmt1.setString(1,search);
stmt1.execute();
rs1=(ResultSet) stmt1.getResultSet();
while(rs.next())
{
count++;
anArray[i]=rs.getString("subject");
System.out.println(anArray[i]);
i++;
}
while(rs1.next())
{
anArray[i]=rs1.getString("subject");
System.out.println(anArray[i]);
i++;
}
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("problem in connection");
}
这是我的java代码,其中包含Resultset和数组。请帮助我。
答案 0 :(得分:0)
只需根据您的要求将结果集保存在任何范围内,如请求或会话属性:
request.setAttribute("resultset", resultset);
现在从scoped属性中获取数据(意味着在jsp页面中获取数组值)
<logic:iterate id="item" name="resultset" indexId="idx">
<tr>
<td align="center"><bean:write name="idx"/></td>
<td align="center" ><bean:write name="item" property="eid"/></td>
<td align="center" ><bean:write name="item" property="fname"/></td>
<td align="center" ><bean:write name="item" property="lname"/></td>
<td align="center" ><bean:write name="item" property="designation"/></td>
<td align="center" ><bean:write name="item" property="email"/></td>
<td align="center" ><bean:write name="item" property="contact"/></td>
<td align="center" ><bean:write name="item" property="reqdate"/></td>
<td align="center" ><bean:write name="item" property="ipaddress"/></td>
<td align="center" ><html:radio name="item" property="adminchoice" indexed="true" value="approved" /></td>
<td align="center" ><html:radio name="item" property="adminchoice" indexed="true" value="blocked" ></td>
<td align="center" ><html:radio name="item" property="adminchoice" indexed="true" value="deleted" /></td>
</tr>
</logic:iterate>
希望它能帮到你....!