• Post Reply Bookmark Topic Watch Topic
  • New Topic

response.sendRedirect  RSS feed

 
pankaj patil
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

in my servlet i have checked the session information.
if it is invalid i am forwarding it to welcome page by using
response.sendRedirect("/prac/");

where the prac is the project name.

is it possible to redirect to the context without giving the project name
i have tried response.sendRedirect("/");
but it does not work

Pankaj
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Taken from javadoc of HTTPServletResponse Ver 2.4.

If the location is relative with a leading '/' the container interprets it as relative to the servlet container root.


You have to use the context path also as it says that if you start with a '/' then it is relative to servlet container root , not the current application's root.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example:



By reading the contextPath at runtime and building your relative URLs this way, you future proof your app against changes in the application's name.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!