Note that there are some explanatory texts on larger screens.

plurals
  1. POStruts 2 Iterator tag not working in jsp?
    primarykey
    data
    text
    <p>I am trying to display some values from a table. I am passing the values to an object of "user" class which contains the getters and setters after which am passing the object in a list. However am not able to view the values from a jsp file using iterator tag. UserDetail class contains the getters and setters for test1 and test2 variables.</p> <p>Please find the below code.</p> <p><strong>success.jsp</strong></p> <pre><code>&lt;%@ taglib uri="/struts-tags" prefix="s" %&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h3&gt;All Records:&lt;/h3&gt; &lt;s:iterator value="list"&gt; &lt;fieldset&gt; &lt;s:property value="test1"/&gt;&lt;br/&gt; &lt;s:property value="test2"/&gt;&lt;br/&gt; &lt;/fieldset&gt; &lt;/s:iterator&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>test.java</strong></p> <pre><code>package com.abc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; public class test { private String test1; private String test2; ArrayList&lt;UserDetails&gt; list=new ArrayList&lt;UserDetails&gt;(); public String execute() { try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test3", "test","test"); PreparedStatement ps=conn.prepareStatement("SELECT * from testtable where data = "+test1); ResultSet rs = ps.executeQuery(); while(rs.next()) { UserDetails user = new UserDetails(); user.setTest1(rs.getInt(1)); user.setTest2(rs.getString(2)); list.add(user); } } catch (Exception e) { e.printStackTrace(); } return "SUCCESS"; } } </code></pre> <p>Please Guide.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload