How can I call a JSP page from a Servlet. I have the required data in session variables, and want to access that data from JSP. I don't know how to redirect to JSP page. Please give sample.
Thanks.
Printable View
How can I call a JSP page from a Servlet. I have the required data in session variables, and want to access that data from JSP. I don't know how to redirect to JSP page. Please give sample.
Thanks.
You can either use the HttpServletResponse.sendRedirect() method or using HttpServletRequest.forward() method. This two method have a different behavior. The sendRedirect() will cause a browser to initiate a new request to the server, this means you have to keep your data so it will arrive on the next target page, for example you can keep the data in session scope.
While the forward method will just forward the request to another target without asking the browser to initiate a new request, or the browser didn't know that you request is processed in another page.