I am trying to pass arraylist object from a jsp page on submitting a form to a servlet.
Code of jsp page :-
<form action="NewServlet">
<%
ArrayList al=new ArrayList();
al.add("abc");
al.add("xyz");
request.setAttribute("allproducts", al);
%>
<input type="submit" value="Show"></form>
Code of NewServlet :-
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
ArrayList al=(ArrayList)request.getAttribute("allproducts");
System.out.print(al.get(0));
}
When I run this code , I am getting NullPointerException
at line "System.out.print(al.get(0))".
Can anyone tell me why is it happening?
Also what should I do if I want to use this al object in servlet ?