Ajouve
Ajouve

Reputation: 10049

redirect to another url

I'm doing redirection in my servlets but the url is always the same and my post and gat parameters doesn't disappear

RequestDispatcher dispatcher = request.getRequestDispatcher("/");
dispatcher.forward(request, response); 

In this exemple the url will not change, but the fetch page will be "/" And my post and get are not destroyed.

I'm trying to find a real redirection as

header("location:/");

in PHP.

Upvotes: 2

Views: 88

Answers (1)

Ravi K Thapliyal
Ravi K Thapliyal

Reputation: 51721

Use sendRedirect() to do a true redirection instead of internal dispatch.

response.sendRedirect("/");
  • Address bar url reflects the change
  • Done through the client browser (using location: header)
  • New request object is created (previous get/post parameters are destroyed)

Upvotes: 2

Related Questions