title: unable to send or pass object arraylist from servlet to jsp using jstl
body: <p>Hey guys I m trying to show list of users from the database table by passing arraylist object from servlet to jsp but unable to do so.</p>
  
  <p>1.> Login.java</p>
  
  <pre><code>package com.pms.servlet;
  
  public class Login {
  
  int id;
  String fname;
  String mname;
  String lname;
  String uname;
  String utype;
  String emailid;
  String mobno;
  String address;
  String password1;
  String password2;
  
  
  public int getUid()
  {
      return id;
  }
  public void setUid(int id)
  {
      this.id=id;
  }
  public String getFname()
  {
      return fname;
  }
  public void setFname(String fname)
  {
      this.fname=fname;
  }
  public String getMname()
  {
      return mname;
  }
  public void setMname(String mname)
  {
      this.mname=mname;
  }
  public String getLname()
  {
      return lname;
  }
  public void setLname(String lname)
  {
      this.lname=lname;
  }
  public String getUname()
  {
      return uname;
  }
  public void setUname(String uname)
  {
      this.uname=uname;
  }
  public String getUtype()
  {
      return utype;
  }
  public void setUtype(String utype)
  {
      this.utype=utype;
  }
  public String getEmailid()
  {
      return emailid;
  }
  public void setEmailid(String emailid)
  {
      this.emailid=emailid;
  }
  public String getMobno()
  {
      return mobno;
  }
  public void setMobno(String mobno)
  {
      this.mobno=mobno;
  }
  public String getAddress()
  {
      return address;
  }
  public void setAddress(String address)
  {
      this.address=address;
  }
  public String getPassword1()
  {
      return password1;
  }
  public void setPassword1(String password1)
  {
      this.password1=password1;
  }
  public String getPassword2()
  {
      return password2;
  }
  public void setPassword2(String password2)
  {
      this.password2=password2;
  }
  }
  </code></pre>
  
  <p>2.> Delete.java</p>
  
  <pre><code>package com.pms.servlet;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import java.sql.Statement;
  import java.util.ArrayList;
  
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  import javax.swing.text.html.HTMLDocument.Iterator;
  
  /**
  * Servlet implementation class Delete
   */
  @WebServlet("/Delete")
  public class Delete extends HttpServlet {
  private static final long serialVersionUID = 1L;
  
  /**
   * @see HttpServlet#HttpServlet()
   */
  public Delete() {
      super();
      // TODO Auto-generated constructor stub
  }
  
      /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
      }
  
      /**
       * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
  
          Connection conn=null;
          String url="jdbc:mysql://localhost:3306/";
          String dbName="projectmanagement";
          String driver="com.mysql.jdbc.Driver";
          String dbUserName="root";
          String dbPassword="root";
  
          try{
          Class.forName(driver).newInstance();
          conn = DriverManager.getConnection(url+dbName,dbUserName,dbPassword);
          String strQuery="select * from user";
          System.out.println("The sql is " +strQuery);
      Statement st= conn.createStatement();
          ResultSet rs= st.executeQuery(strQuery);
  
          ArrayList&lt;Login&gt; al=new ArrayList&lt;Login&gt;();
  
      while(rs.next())
      {
          Login l=new Login();
          //l.setUid(rs.getInt("uid"));
          l.setFname(rs.getString("fname"));
          l.setMname(rs.getString("mname"));
          l.setLname(rs.getString("lname"));
          l.setUname(rs.getString("uname"));
          l.setUtype(rs.getString("utype"));
          l.setEmailid(rs.getString("emailid"));
          l.setMobno(rs.getString("mobno"));
          l.setAddress(rs.getString("address"));
          System.out.println(l);
          System.out.println(al);
          al.add(l);
  
          request.setAttribute("ual",al);
          System.out.println(al);
          }
  
          rs.close();
          st.close();
          }
          catch(Exception e)
          {
              e.printStackTrace();
          }
  
  
  
          response.setContentType("text/html");
  
  
      }
  
   }
  </code></pre>
  
  <p>3.> successful.jsp</p>
  
  <pre><code> &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%&gt;
   &lt;%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&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;body&gt;
  
   &lt;form name="delete-user" action="Delete" method="post"&gt;
          &lt;p&gt;&lt;b&gt;&lt;i&gt;List of user details:&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;
          &lt;table border="1"&gt;
  
              &lt;tr&gt;
              &lt;th&gt;First Name&lt;/th&gt;
              &lt;th&gt;Middle Name&lt;/th&gt;
              &lt;th&gt;Last Name&lt;/th&gt;
              &lt;th&gt;User Name&lt;/th&gt;
              &lt;th&gt;Usertype&lt;/th&gt;
              &lt;th&gt;Email id&lt;/th&gt;
              &lt;th&gt;Mobile No&lt;/th&gt;
              &lt;th&gt;Address&lt;/th&gt;
              &lt;th&gt;Delete User&lt;/th&gt;
              &lt;/tr&gt;
          &lt;c:forEach items="${ual}" var="u"&gt;
              &lt;tr&gt;
              &lt;td&gt;&lt;c:out value="${u.fname}"&gt;&lt;/c:out&gt;&lt;/td&gt;
              &lt;td&gt;&lt;c:out value="${u.mname}"&gt;&lt;/c:out&gt;&lt;/td&gt;
              &lt;td&gt;&lt;c:out value="${u.lname}"&gt;&lt;/c:out&gt;&lt;/td&gt;
              &lt;td&gt;&lt;c:out value="${u.uname}"&gt;&lt;/c:out&gt;&lt;/td&gt;
              &lt;td&gt;&lt;c:out value="${u.utype}"&gt;&lt;/c:out&gt;&lt;/td&gt;
              &lt;td&gt;&lt;c:out value="${u.emailid}"&gt;&lt;/c:out&gt;&lt;/td&gt;
              &lt;td&gt;&lt;c:out value="${u.mobno}"&gt;&lt;/c:out&gt;&lt;/td&gt;
              &lt;td&gt;&lt;c:out value="${u.address}"&gt;&lt;/c:out&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="button" name="delete" value="Delete User"/&gt;    &lt;/td&gt;
              &lt;/tr&gt; 
          &lt;/c:forEach&gt;
          &lt;/table&gt;
          &lt;/form&gt;
    &lt;/body&gt;
    &lt;/html&gt;
  </code></pre>
  
  <p>Here, I m unable to pass the object arraylist for list of users from servlet to jsp. There no run time or compile time error. I m able to show list of users by writing query in jstl sql tag but unable to do so in java servlet code. :(</p>
  
  <p>In web.xml also everything is fine and database connectivity is also properly done. Then where m I going wrong.</p>
  
  <p>I checked various catch's and tutorial's but unable to do so. </p>
  
  <p>Please Help. </p>