File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sendRedirect()

 
sandeep Talari
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference between the

response.sendRedirect("/foo/doStuff.html")(with forward slash)

and

response.sendRedirect("foo/doStuff.html")(without forward slash)

please explain
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Relative path comes into 2 ways.

with"/" and without "/"


1. without using "/": container will look the jsp from current directory.

2. using "/" :container will look the jsp from ROOT directory.

i prefer 2nd one.

Hope This helps
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First one specifies the absolute path (context specific path) while the second one specifies the relative path.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sudhir nim:
First one specifies the absolute path (context specific path) while the second one specifies the relative path.



No. it is also one kind of relative path.

Note:

absolute path means you have to give whole url starting from http://...
 
Amit Ghorpade
Bartender
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by seetharaman venkatasamy
using "/" :container will look the jsp from ROOT directory.


Instead of ROOT, context root is the more appropriate term.
And BTW the original poster has mentioned html files and not jsp.

Although that wont change the answer, it might confuse a bit to beginners


Hope this helps
 
Amit Ghorpade
Bartender
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And sandeep Talari please UseAMeaningfulSubjectLine.
So that you get more useful responses.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Amit
 
Amit Ghorpade
Bartender
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Amit

You are welcome
 
Rohith Kumar Singh
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both the paths mentioned are relative only. The one for which '/' precedes the path will be relative to the underlying context root and for the other one where '/' is not preceding the path it'll be relative to the current request being serviced.

Cheers,
Rohit
[ August 27, 2008: Message edited by: Bear Bibeault ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's important to remember that merely adding a forward slash to the beginning of a relative url will not cause the browser to look in the root of your servlet context. Browsers know nothing about servlet contexts.

In order to build a proper context relative link you need to explicitly add the contextPath yourself. We have two articles that explain how to do this in our JSP FAQ:
http://faq.javaranch.com/java/RelativeLinks
and
http://faq.javaranch.com/java/ResourceUrlProblems

The both cover the same thing but are written in different ways.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic