[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 765
  • Last Modified:

display the result in the form of table in JSP

Hello,

I am using Beans and JSP and vector to pull the data from the database and showing it in the JSP.

I want to display the result in the JSP like this
The result for Logical Name **** is:  **********row1
 (cell1)Vendor: (cell2)ATT Paradyne *********row2
(cell1)Model: (cell2)Comshpere 3610 *********row3
.....and so on

but I am getting the result like this

The result for Logical Name *** is:  (row1)
 Vendor: ATT Paradyne Model: Comshpere 3610 SerialNumber: 4041095 OpSys: All Function: null Group: Network Facility: A1 Grid-AAA: null Grid-999: null Cabinet: Bay-8 Row: NSC  (row2 and all in one cell)

This is the code I have used:
**********************JSP*************************
......
<%
     Simple_SearchBean.processRequest(request,session);
          Vector Ssresult_vec = new Vector ((Vector) Simple_SearchBean.getSsresult_vec());
                        ListIterator iter_res = Ssresult_vec.listIterator();
%>
<table border ="1">
       <tr>
       <th>The result for Logical Name <%=request.getParameter("Logicalnm_lst")%>  is:  </th>
                </tr>
       <tr>
                            <% while (iter_res.hasNext()) {
                      String value = (String)iter_res.next();
                %>
            <td>  <%=value%> </td>
        </tr>
       <% } %>      
 </table>

*******************Bean********************
try {
        st=conn.createStatement();                       
       rs=st.executeQuery("Select Vendor,Model,[Serial Number],OpSys,Function,Group,Facility,[Grid-Aaa],[Grid-999],Cabinet,Row from [Base Inventory Table] where [Logical Name] = '"+request.getParameter("Logicalnm_lst")+"'");
      Ssresult_vec.clear();
              while(rs.next()) {
        c1 = "Vendor: "+ rs.getString("Vendor");
        c2 = "Model: " + rs.getString("Model");
        c3 = "SerialNumber: " + rs.getString("Serial Number");
            .....
                   Ssresult_vec.addElement( c1+ "\n" +c2+ "\n" + c3+ "\n" + c4+ "\n" +c5+ "\n" +c6+ "\n" +c7+ "\n" +c8+ "\n" +c9+ "\n" +c10+ "\n" +c11+ "\n" );
}
}catch(SQLException exe){}

Do I have to add a for loop for the table too in the jsp?

Please help,
Thanks


0
nubee
Asked:
nubee
  • 3
  • 2
1 Solution
 
kiranhkCommented:
change this to

     <tr>
                          <% while (iter_res.hasNext()) {
                    String value = (String)iter_res.next();
              %>
          <td>  <%=value%> </td>
       </tr>


**************************

 
                          <% while (iter_res.hasNext()) {
    <tr>
                    String value = (String)iter_res.next();
              %>
          <td>  <%=value%> </td>
       </tr>

     <% } %>  
0
 
nubeeAuthor Commented:
Thanks Kiranhk for your quick response,

I tried it like you said:

<% while (iter_res.hasNext()) {%>
              <tr>
             <% String value = (String)iter_res.next();%>
             
             
      <td> <%=value%> </td>
        <tr/>

Its still the same :(
0
 
nubeeAuthor Commented:

Do you think its because of the Bean code?
here I am already attaching the string Vendor, Model etc..

c1 = "Vendor: "+ rs.getString("Vendor");
       c2 = "Model: " + rs.getString("Model");
       c3 = "SerialNumber: " + rs.getString("Serial Number");
            .....
                 Ssresult_vec.addElement( c1+ "\n" +c2+ "\n" + c3+ "\n" + c4+ "\n" +c5+ "\n" +c6+ "\n" +c7+ "\n" +c8+ "\n" +c9+ "\n" +c10+ "\n" +c11+ "\n" );
}
0
 
kiranhkCommented:
yes...... sorry, didnt go thro' properly earlier

If you do like this

Ssresult_vec.addElement( c1+ "\n" +c2+ "\n" + c3+ "\n" + c4+ "\n" +c5+ "\n" +c6+ "\n" +c7+ "\n" +c8+ "\n" +c9+ "\n" +c10+ "\n" +c11+ "\n" );

then u need to use StringTokenizer then only you can print it line by line....

so do this instead

while(rs.next()) {
       c1 = "Vendor: "+ rs.getString("Vendor");
Ssresult_vec.addElement( c1);
       c2 = "Model: " + rs.getString("Model");
Ssresult_vec.addElement( c1);
       c3 = "SerialNumber: " + rs.getString("Serial Number");
Ssresult_vec.addElement( c1);
            .....
}

then have the html code i gave above
0
 
nubeeAuthor Commented:
SUPER.It worked.

Thanks kiranhk
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now