Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy the ArrayList is Returning empty strings [] [] []?
    primarykey
    data
    text
    <p>this is my DB enquiry function</p> <pre><code> public static List&lt;UserPass&gt; selectAllUser() { ConnectionPool pool = ConnectionPool.getInstance(); Connection connection = pool.getConnection(); PreparedStatement ps = null; ResultSet rs = null; List&lt;UserPass&gt; usersPass = new ArrayList&lt;UserPass&gt;(); String query = "select * from UserPass"; try{ ps = connection.prepareStatement(query); rs = ps.executeQuery(); while(rs.next()){ UserPass users = new UserPass(); users.setUserName(rs.getString("user_name")); usersPass.add(users); } return usersPass; </code></pre> <p>and this is my UserPass object get function</p> <pre><code> public ArrayList&lt;UserPass&gt; getusernames(){ return usernames; } </code></pre> <p>my servlet dopost is simply this </p> <pre><code> request.setAttribute("users", UserPassDb.selectAllUser()); String forward = "/testpage.jsp"; RequestDispatcher view = request.getRequestDispatcher(forward); view.forward(request, response); </code></pre> <p>and my display jsp page is </p> <pre><code> &lt;form action="TestServlet" method="post"&gt; &lt;input type="submit"&gt; &lt;/form&gt; &lt;c:forEach var="user" items="${users}"&gt; &lt;c:out value="${user.usernames}"/&gt; &lt;/c:forEach&gt; </code></pre> <p>UserPass Class </p> <pre><code> /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package business; import java.io.Serializable; import java.util.ArrayList; /** * * @author One */ public class UserPass implements Serializable { public String username; public String password; public ArrayList&lt;UserPass&gt; usernames; public UserPass(){ this.username =""; this.password =""; this.usernames = new ArrayList&lt;UserPass&gt;(); } public void setUserName(String username) { this.username = username; } public String getUserName(){ return username; } public ArrayList&lt;UserPass&gt; getusernames(){ return usernames; } public void setusernames(ArrayList&lt;UserPass&gt; a){ this.usernames = a; } } </code></pre> <p>tried changing this it tells me property doesn't exist when it does as far as i understand. am sure am wrong</p> <p>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.
    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