Note that there are some explanatory texts on larger screens.

plurals
  1. POArraylist + database + servlet + DAO
    primarykey
    data
    text
    <p>Hello i'm new to hava and i'm having a problem viewing my records from an arraylist in JSP page, whenever i load the page i get: [content.animalBean@1e8614a, content.animalBean@14b52aa, content.animalBean@2026f3, content.animalBean@dd20b6, content.animalBean@18eb00c] 1 which is not the database records here is my code: selectAnimalServlet:</p> <pre><code>package content; import java.util.Iterator; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class selectAnimalServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { try { List&lt;animalBean&gt; beans = DAO.selectListAnimal(); request.setAttribute("beans", beans); request.getRequestDispatcher("checkAnimal.jsp").forward(request, response); } catch (Throwable theException) { System.out.println(theException); } } } </code></pre> <p>AnimalBean:</p> <pre><code>package content; public class animalBean { private String animalName; private String animalDob; private String animalGender; private String animalSource; private String animalBreed; private String animalRemark; public String getAnimalName() {return animalName;} public String getAnimalDob() {return animalDob;} public String getAnimalGender() {return animalGender;} public String getAnimalSource() {return animalSource;} public String getAnimalBreed() {return animalBreed;} public String getAnimalRemark() {return animalRemark;} public void setAnimalName(String animalName) {this.animalName = animalName;} public void setAnimalDob(String animalDob) {this.animalDob = animalDob;} public void setAnimalGender(String animalGender) {this.animalGender = animalGender;} public void setAnimalSource(String animalSource) {this.animalSource = animalSource;} public void setAnimalBreed(String animalBreed) {this.animalBreed = animalBreed;} public void setAnimalRemark(String animalRemark) {this.animalRemark = animalRemark;} } </code></pre> <p>DAO class:</p> <pre><code>package content; import java.sql.*; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class DAO { static Connection currentCon = null; static ResultSet rs = null; public static loginAuth login(loginAuth bean) { //preparing some objects for connection Statement stmt = null; String username = bean.getUsername(); String password = bean.getPassword(); String searchQuery = "select * from user where username='" + username + "' AND password='" + password + "'"; // "System.out.println" prints in the console; Normally used to trace the process System.out.println("Your user name is " + username); System.out.println("Your password is " + password); System.out.println("Query: "+searchQuery); try { //connect to DB currentCon = dbConnection.getConnection(); stmt=currentCon.createStatement(); rs = stmt.executeQuery(searchQuery); boolean more = rs.next(); // if user does not exist set the isValid variable to false if (!more) { System.out.println("Sorry, you are not a registered user! Please sign up first"); bean.setValid(false); } //if user exists set the isValid variable to true else if (more) { String firstName = rs.getString("FirstName"); String lastName = rs.getString("LastName"); System.out.println("Welcome " + firstName); bean.setfname(firstName); bean.setlname(lastName); bean.setValid(true); } } catch (Exception ex) { System.out.println("Log In failed: An Exception has occurred! " + ex); } //some exception handling finally { if (rs != null) { try { rs.close(); } catch (Exception e) {} rs = null; } if (stmt != null) { try { stmt.close(); } catch (Exception e) {} stmt = null; } if (currentCon != null) { try { currentCon.close(); } catch (Exception e) { } currentCon = null; } } return bean; } public static List&lt;animalBean&gt; selectListAnimal() throws SQLException { Statement stmt = null; List&lt;animalBean&gt; beans = new ArrayList&lt;animalBean&gt;(); try { currentCon = dbConnection.getConnection(); String animalSearchQuery = "select a.aname ,a.dob, a.gender , a.source, s.sname, a.remark from animal as a , specie as s where a.specie_id = s.specie_id and a.available ='y'"; stmt=currentCon.createStatement(); rs = stmt.executeQuery(animalSearchQuery); while (rs.next()) { animalBean bean = new animalBean(); bean.setAnimalName(rs.getString("aname")); bean.setAnimalDob(rs.getString("dob")); bean.setAnimalGender(rs.getString("gender")); bean.setAnimalSource(rs.getString("source")); bean.setAnimalBreed(rs.getString("sname")); bean.setAnimalRemark(rs.getString("remark")); beans.add(bean); } } finally { if (rs != null) try { rs.close(); } catch (SQLException logOrIgnore) {} if (stmt != null) try { stmt.close(); } catch (SQLException logOrIgnore) {} if (currentCon != null) try { currentCon.close(); } catch (SQLException logOrIgnore) {} } return beans; } } </code></pre> <p>and last the JSP page animalCheck.jsp:</p> <pre><code>&lt;%@ page language="java" contentType="text/html; charset=windows-1256" pageEncoding="windows-1256" import="content.animalBean" import="content.DAO" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=windows-1256"&gt; &lt;title&gt;Animal list&lt;/title&gt; &lt;link rel="stylesheet" href="./css/styles.css" type="text/css"/&gt; &lt;/head&gt; &lt;body&gt; &lt;table class="title"&gt; &lt;tr&gt;&lt;th&gt;Zoo keeper&lt;/th&gt;&lt;/tr&gt; &lt;/table&gt; &lt;h1&gt;Animal list&lt;/h1&gt; &lt;center&gt; &lt;table width="100 % " id='table1' border="1" cellspacing="2" cellpadding="2"&gt; &lt;tr class="tab-highlighted-2"&gt; &lt;td class="tab-highlighted-2" width="15"&gt; &lt;div align="left"&gt;Name&lt;/div&gt; &lt;/td&gt; &lt;td class="tab-highlighted-2" width="20"&gt; &lt;div align="left"&gt;Age&lt;/div&gt; &lt;/td&gt; &lt;td class="tab-highlighted-2" width="15"&gt; &lt;div align="left"&gt;Gender&lt;/div&gt; &lt;/td&gt; &lt;td class="tab-highlighted-2" width="15"&gt; &lt;div align="left"&gt;Status&lt;/div&gt; &lt;/td&gt; &lt;td class="tab-highlighted-2" width="15"&gt; &lt;div align="left"&gt;Breed&lt;/div&gt; &lt;/td&gt; &lt;td class="tab-highlighted-2" width="15"&gt; &lt;div align="left"&gt;Remarks&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;c:forEach items="${beans}" var="view"&gt; &lt;tr&gt; &lt;td&gt;${view.animalName} &lt;/td&gt; &lt;td&gt;${view.animalDob}&lt;/td&gt; &lt;td&gt;${view.animalGender}&lt;/td&gt; &lt;td&gt;${view.animalSource}&lt;/td&gt; &lt;td&gt;${view.animalBreed}&lt;/td&gt; &lt;td&gt;${view.animalRemark}&lt;/td&gt; &lt;/tr&gt; &lt;/c:forEach&gt; &lt;/table&gt; &lt;/center&gt; &lt;/body&gt;&lt;/html&gt; </code></pre> <p>I've been struggeling on this since 2 days and i checked many websites and followed many guides but still nothing worked for me :( I appreciate any kind of help </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.
 

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