【问题标题】:how to call Array of java class in jsp file?如何在jsp文件中调用java类的数组?
【发布时间】:2013-04-17 12:03:42
【问题描述】:

您好,我想在 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 代码,其中包含结果集和数组。请帮助我。

【问题讨论】:

标签: java jsp resultset


【解决方案1】:

根据您的要求(如请求或会话属性)将结果集保持在任何范围内:

request.setAttribute("resultset", resultset);

现在从你的作用域属性中获取数据(意味着在你的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>

希望对你有所帮助....!

【讨论】:

    猜你喜欢
    • 2014-06-13
    • 1970-01-01
    • 2012-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-31
    • 2017-04-29
    • 1970-01-01
    相关资源
    最近更新 更多