title: Send ArrayList from a JSP page to servlet when submitting a form
body: <p>I want to retrieve the <code>ArrayList</code> from a JSP page to servlet when submitting the form on the JSP page. I am trying following code:</p>
  
  <p>Code of <code>Pass.jsp</code> is:</p>
  
  <pre><code>&lt;form action="GetListServlet"&gt;
  &lt;%
      ArrayList al=new ArrayList();
      al.add("Naman");
      al.add("Gupta");
      request.setAttribute("allnames", al); 
  %&gt;
  &lt;input type="submit" value="Show List"&gt;&lt;/form&gt;
  </code></pre>
  
  <p><code>doGet()</code> method of <code>GetListServlet</code> is :-</p>
  
  <pre><code>protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException 
  {
      ArrayList al=(ArrayList)request.getAttribute("allnames");
      System.out.print(al.get(0));
  } 
  </code></pre>
  
  <p>But I am getting <code>NullPointerException at System.out.print(al.get(0))</code>.</p>
  
  <p>Can anyone tell me how can I get arraylist of jsp page on the servlet page ? </p>