I'm trying to display data in JSP by a servlet but I get a null object after getting the parameter:
This is my doGet function in the servlet:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
EntityManagerFactory emf = Persistence.createEntityManagerFactory("AdministracionWeb");
StudentManager sm = new StudentManager();
sm.setEntityManagerFactory(emf);
List<Student> result = sm.getAllStudents();
// result contains a correct value
//out.println(result);
request.setAttribute("stList", result);
request.getRequestDispatcher("students.jsp").forward(request,response);
}
And this is how I read the result:
<%
List<Student> stList = (List<Student>) request.getAttribute("stList");
// stList here is null (why???)
Student st = new Student();
for (int i = 0; i < stList.size(); i++){
st = stList.get(i);
...
%>
Thanks in advance!!