Wrox Home  
Search P2P Archive for: Go

  Return to Index  

servlets thread: Re: servlets digest: January 09, 2003


Message #1 by "Paul Byford" <p_byford@h...> on Fri, 10 Jan 2003 15:48:38 +0000

Lior,

The methods you are using sound ok. i think u are just forwarding to the  
incorrect place by using an incorrect path.

Obviously when calling ) the final place the user is sent will depend upon 
the value of 'path', and more importantly the form of 'path'.

All forwarding will be relative to the servlet that ) is called from.

For example;

assume;
site context is /webApp/
all servlets are in /webApp/servlet/
jsps are located in /webApp/jsp/
a test servlet calls getRequestDispatcher("path").forward(); to forward the 
user to the path

if;
path = "jsp/Page.jsp"
user forward to "/webApp/servlet/jsp/Page.jsp"

if;
path = "aFolder/jsp/Page.jsp"
user forward to "/webApp/servlet/aFolder/jsp/Page.jsp"

this happens because all forwarding will be relative to the servlet folder. 
In the above examples the servelt forwards users to a position below it in 
the hierarchy.

The jsp folder however is on the same level as the servlet folder. To 
forward to this level a / must be inserted at the front of the path varible. 
This tells the servlet to forward the user relative to the serlvet context, 
which in this case is webApp, and not relative to the servlet.

for example;

if;
path = "/jsp/Page.jsp"
user forward to "/webApp/jsp/Page.jsp"

if;
path = "/aFolder/jsp/Page.jsp"
user forward to "/webApp/aFolder/jsp/Page.jsp"


Hope this explains things.

paul


>From: "Servlets digest" <servlets@p...>
>Reply-To: "Servlets" <servlets@p...>
>To: "servlets digest recipients" <servlets@p...>
>Subject: servlets digest: January 09, 2003
>Date: Fri, 10 Jan 2003 00:06:44 -0000
>
>-----------------------------------------------
>When replying to the digest, please quote only
>relevant material, and edit the subject line to
>reflect the message you are replying to.
>-----------------------------------------------
>
>The URL for this list is:
>http://p2p.wrox.com/list.asp?list=servlets
>SERVLETS Digest for Thursday, January 09, 2003.
>
>1. ServletContext Question
>
>----------------------------------------------------------------------
>
>Subject: ServletContext Question
>From: "Lior Shliechkorn" <lior@f...>
>Date: Thu, 9 Jan 2003 18:12:26
>X-Message-Number: 1
>
>Hello Everyone,
>
>I'm very confused about the ServletContext mechanics. I have a servlet
>that authorizes a user entering the application, and I used the
>getServletContext() in order to be able to forward the user to the next
>page. However, when I get the RequestDispatcher and forward to a
>welcome.jsp for example, the page is being directed to the same path as
>that of the servlet.
>
>I have the servlet mapped as /servlet/Example and then when I forward to a
>page who's path is /webApp/, I get an error that the page
>cannot be found under /servlet/jsp/Page.jsp. How can I fix this issue? Is
>there a way to reset the context or something? I'm totally confused.
>
>Thank you very much,
>Lior
>
>
>---
>
>END OF DIGEST
>


_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE* 
http://join.msn.com/?page=features/junkmail


  Return to Index