Does the servlet send a redirect to the welcome page?

How can I force the servlet to redirect to the welcome page without specifying the exact path? How simple is changing the path to the topmost:

response.sendRedirect("/"); 

Which is clearly not working.

+4
source share
2 answers
 response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + "/")); 

The encodeRedirectURL call is necessary if you want to support session tracking for browsers with cookies disabled (i.e., by rewriting URLs).

+7
source

Thanks to Michael-O above, following the solution:

 response.sendRedirect(request.getContextPath()); 
+2
source

Source: https://habr.com/ru/post/1436790/


All Articles