Note that there are some explanatory texts on larger screens.

plurals
  1. POFill drop down box with values from a class
    primarykey
    data
    text
    <p>i have this as JSP page and i want a combobox to fill up the values from a table in the database. I have a class Assembly and a Class Assemblys, in Assemblys i make every record an instance of Assembly and put it in a list. But i can't retrieve it in JSTL? Why is this?</p> <pre><code> &lt;%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&gt; ..... &lt;select name = "assembly"&gt; &lt;c:forEach var ="item" items="${Assemblys}"&gt; &lt;option value="${item.id}"&gt;${item.Name}&lt;/option&gt; &lt;/c:forEach&gt; &lt;/select&gt; </code></pre> <p>This as the class Assembly Class</p> <pre><code> public class Assembly { public String Name; public int cost; public int id; public Assembly(String Name, int cost, int id) { this.Name = Name; this.cost = cost; this.id = id; } } </code></pre> <p>And this is the class Assemblys</p> <pre><code> public class Assemblys { List&lt;Assembly&gt; list = new ArrayList&lt;Assembly&gt;(); public Assemblys(){ list = getAssemblys(); } private List&lt;Assembly&gt; getAssemblys() { try { Connection conn = MysqlConnect.conn(); PreparedStatement pstmt = null; ResultSet rs = null; String Query = "Select * from tbl_assembly"; pstmt = conn.prepareStatement(Query); rs = pstmt.executeQuery(); while (rs.next()) { Assembly ass = new Assembly(rs.getString(2),rs.getInt(3),rs.getInt(1)); list.add(ass); } conn.close(); } catch (SQLException ex) { Logger.getLogger(Assemblys.class.getName()).log(Level.SEVERE, null, ex); } return list; } } </code></pre> <p>Why is my drop down list blank? I don't get it. I thought this was the right code?</p> <p>Many thanks in advance!</p>
    singulars
    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.
 

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