• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I get to the root of the application.

 
Tom Kowalski
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have got problem, and I really need your help ^^.

Let's assume that the user is at this page:
http://localhost:8080/WebIndex/test/student/log.jsp

Now I would like to redirect him to the
http://localhost:8080/WebIndex/index.jsp

how can I do it?

I don't want to write something like this:

becouse this address is temporary of course. I was trying with RequestDispatcher:

but it is opening this page:
http://localhost:8080/WebIndex/test/student/index.jsp


 
Pawel Nowacki
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you could use request.getContextPath() to build a path to the given resource:


Not sure, if its the best solution, though.
 
Tom Kowalski
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
// ok
 
Omer Haderi
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the following code: should get you to the root of the server: http://localhost:8080/index.jsp

HF page 136, relative paths:
if the path starts with the forward slash / then the container builds the complete URL relative to the web container itself
if you do NOT provide the forward slash / then the container builds the URL relative to the original request URL

the spec does not say anything about the forward slash!!!

maybe you do not use the forward slash

enjoy!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Omer Haderi wrote:maybe you do not use the forward slash

Yes. He does. In fact, the answer prefixing the context path is the correct answer.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic