I am trying to pass the my DTO object from jsp to servlet using session object but i'm getting null pointer exception initially i tried with request object which is giving same error hence i moved to session object.
in first servlet
request.getSession().setAttribute("datadto", dataDTO);
request.getRequestDispatcher("success.jsp").forward(request, response);
in jsp
<%
DataDTO dataDTO = (DataDTO) request.getAttribute("datadto");
HttpSession session420 = request.getSession();
session420.setAttribute("object", dataDTO);
%>
in second servlet
HttpSession session=request.getSession(false);
DataDTO dataDTO = (DataDTO) session.getAttribute("object");
MyService myService = ServiceFactory.getMyService();
myService.generateExcel(dataDTO); <--nullpointerexception
on googling i found the following link I implemented as he said still i'm getting null pointer exception
in jsp
DataDTO dataDTO = myService.getData(keyword, nor);
String myObjectId = UUID.randomUUID().toString();
request.getSession().setAttribute(myObjectId, dataDTO);
request.setAttribute("myObjectId", myObjectId);
in second servlet
String myObjectId = request.getParameter("myObjectId");
Object myObject = request.getSession().getAttribute(myObjectId);
DataDTO dataDTO = (DataDTO) myObject;
request.getSession().removeAttribute(myObjectId);
please help me.