Reputation: 2899
I've been through a few tutorials for java servlets and they all show how to display a web page generating in the java code using a servlet. How can I display an existing html page using a servlet?
I figure I need to do something with HttpServletRequest.getRequestDispatcher but not sure exactly what?
Upvotes: 4
Views: 2541
Reputation: 17839
you can do this in two ways:
Request dispatcher
ServletContext context= getServletContext(); RequestDispatcher rd= context.getRequestDispatcher("/somePage.html"); rd.forward(request, response);
Response sendRedirect()
response.sendRedirect("/someUrl.html");
See the difference between the two methods here: RequestDispatcher.forward() vs HttpServletResponse.sendRedirect()
Upvotes: 3