2013-04-24 2 views
0

안녕하세요 저는 두 개의 ResultSet을 JSP 파일에 전달하려고합니다. 나는 두 개의 ResultSet rs와 rs1을 가지고있다. ResultSet을 단일 배열에 모두 저장했습니다. 이제 jsp 파일에 배열을 인쇄하고 싶습니다. 그래서 웹 페이지에서 내 결과를 보여줄 수 있습니다. 친절하게 말해서 어떤 코드를 JSP 파일로 작성해야하는지 알려주세요. 얼마나 많은 파일을 jsp 파일에서 가져와야합니까 .. 친절하게 도와주세요.jsp 파일에서 Java 클래스의 배열을 호출하는 방법?

    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 및 배열을 포함합니다. 친절하게 도와주세요. 로

+1

확인 : http://www.tutorialspot.com/jsp/jstl_core_foreach_tag.htm –

답변

0

그냥 요청 또는 세션 속성 같은 귀하의 요구 사항에 따라 어떤 범위에서 결과 집합을 유지 :

이제
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> 

희망이 ....!

관련 문제