• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlets sendredirect

 
srikanth darbha
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

i have few doubt regarding sendRedirect(String location) in httpresponse.
1)can the location value be an url mapping i.e, like response.sendRedirect("/addAmount") else should it be only sendRedirect("loginhome.html") or sendRedirect("loginhome.jsp")

2)What is meant by relative path ("/") what happens if i dont give relative path ?

please explain me clearly since i am new to servlets technology.


Thanks in advance



 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The URL should be a server-relative URL that starts with the context path.
 
Mohamed Iqzas
Ranch Hand
Posts: 73
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually - "/" takes you to the root.

when you start the url with "/" then append the url to "www.ur-domain-name.com".... this is how the final url will look like.

when you use without "/" - you should append the url to the directory your current page is in.

for ex: if your current url is in "www.ur-domain-name.com/MyApp/html/index.html", and inside index.html:

-> if you use a link with url-"login.html" not starting with slash , then it'll take you to the url - "www.ur-domain-name.com/MyApp/html/login.html"...

-> or if your url is "jsp/login.html", then it'll take you to the url - "www.ur-domain-name.com/MyApp/html/jsp/login.html"...

I have not given you all you need. You can search in google to get clear idea about it. Probably it might be in stackoverflow.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The confusion can be cut by just following the best practice of using server-relative URLs (those that start with the context path) for redirects to resources within the same web app. For external resources, use the full absolute URL. Easy.
 
Mohamed Iqzas
Ranch Hand
Posts: 73
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how is the root path configured in j2ee? when i start a url with "/" it once referred to the root of the server. www.myserver.com

but in another instance it referred to the root of my application directory. www.myserver.com/myApp

is it server specific? any xml file where we need to mention this?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65126
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends upon the servlet container.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic