Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Servlet send redirect to welcome page?

Tags:

java

servlets

How can I force a Servlet redirect to the welcome page without having to specify the exact path? Like just altering the path to the most upper one:

response.sendRedirect("/");

Which does obviously not work.

like image 379
membersound Avatar asked Dec 08 '22 20:12

membersound


2 Answers

response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + "/"));

The call to encodeRedirectURL is necessary if you want to support session tracking for browsers with cookie support disabled (i.e. using URL rewriting).

like image 145
JB Nizet Avatar answered Dec 31 '22 23:12

JB Nizet


Thanks to Michael-O above, following solution:

response.sendRedirect(request.getContextPath());
like image 36
membersound Avatar answered Dec 31 '22 23:12

membersound