Amir Rachum
Amir Rachum

Reputation: 79635

Java servlets: how to display a page?

I'm using a Java Servlet to do some work (validate user login, update session values, etc.) and I want to redirect to an existing JSP page when I'm done. How do I do that?

Upvotes: 1

Views: 185

Answers (3)

Ken Chan
Ken Chan

Reputation: 90447

Apart from using HttpServletResponse.sendRedirect() , you can also set the http response header and status code to SC_MOVED_PERMANENTLY (301) or SC_MOVED_TEMPORARILY (302)

response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);  
response.setHeader("Location", "http://www.xxx.yyy/");

Upvotes: 0

Penkov Vladimir
Penkov Vladimir

Reputation: 939

also to sendRedirect take a look at

 request.getRequestDispatcher("/foo/foo.jsp").forward(request, response);

redirect is useful then you changed some information (e.g. made a post in the forum) so redirecting will prevent double posting.

Upvotes: 2

Zemzela
Zemzela

Reputation: 3080

response.sendRedirect("page.jsp");

Upvotes: 2

Related Questions