• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SendRedirect() - 2 Forms of Relative URL's

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At page 136 of HSFJ,

Imagine the client originally typed in:

http://www.wickedlysmart.com/myApp/cool/bar.do

When the request comes into the servlet named bar.do, the servlet calls sendRedirect() with a URL that doesn't start with a /

sendRedirect("foo/stuff.html");

The container builds the full URL relative to the original request URLAS :
http://www.wickedlysmart.com/myApp/cool/foo/stuff.html

My question is : Does the author assumes that in web.xml, we have
<servlet-mapping>*.do </servlet-mapping>

Even then also /cool/bar.do will match *.do(servlet-mapping), how we decide what is the request URL ?

I am sure :
req.getContextPath() = /myApp
req.getServletpath() = /cool/bar.do

Moreover when i write :
res.sendRedirect("/html/index.html");

the browser takes me to
http://127.0.0.1:8080/html/index.html

but in HFSJ it's written that in this case(where argument to sendRedirect starts with a /) it is relative to the context-root of web application ?
[ March 24, 2007: Message edited by: Sandeep Vaid ]
 
warren li
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you remember wrongly. For sendRedirect( java.lang.String ), if the parameter string starts with /, it is relative to the web-server, not to the web application.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic