You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Simon Senécal <ss...@labvolt.ca> on 2003/02/21 15:35:03 UTC

RequestDispatcher.forward() problem

I need help. (I use Tomcat 4.1.18)

I'm in JSP1 in a webapp (Webapp1) and I use 
RequestDispatcher.forward(request, response) to forward in JSP2 located in 
another webapp (Webapp2). The two webapps are on the same server. The 
forwarding works, but once I'm in the JSP2 (in Webapp2), it looks like I'm 
still in the context of Webapp1, the URL of the request remains the URL of 
JSP1 in Webapp1. However, the servlet API documentation specifically says:

"For a RequestDispatcher obtained via getRequestDispatcher(), the 
ServletRequest object has its path elements and parameters adjusted to 
match the path of the target resource".

Here is a simplified part of the code I use in JSP1:

ServletContext contxt = getServletContext().getContext("/Webapp2");
RequestDispatcher disp = 
contxt.getRequestDispatcher("/JSPinWebapp2.jsp"); 
disp.forward(request, response);

Is this a bug, or is there something that I'm missing or not understanding 
about forwarding?


Simon Senécal
Lab-Volt Québec (Software Development)
418-849-1000 #348
http://www.labvolt.com          


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


RE: RequestDispatcher.forward() problem

Posted by John Trollinger <ja...@trollingers.com>.
There is a single sign on in tomcat, but I have never used it.  You
might want to ask about it in the user mailing list
tomcat-user@jakarta.apache.org or better yet read the archives and see
if this question has already been answered there.

John

> -----Original Message-----
> From: Simon Senécal [mailto:ssenecal@labvolt.ca] 
> Sent: Friday, February 21, 2003 10:12 AM
> To: Tomcat Developers List
> Subject: RequestDispatcher.forward() problem
> 
> 
> Thanks for your reply, John.
> 
> Can you transport data from one webapp to the other when you use the 
> sendRedirect() method? Here is my true problem. I want to 
> transport data 
> such as a username and a password between two webapps (and I 
> don't want to 
> use URL rewriting). The user logs on Webapp1 and after 
> authentification, 
> the user has the choice to go to Webapp2, and I need the username and 
> password to work in Webapp2. As I understand it, I can't use 
> the session 
> object to transport data because each Webapp has it's own 
> session object. 
> So I thought of using the forwarding method and use the 
> request object to 
> store my data (with setAttribute and getAttribute). It works, 
> but like I 
> said in my previous email, after forwarding, I'm still in the 
> context of 
> Webapp1.
> 
> Simon.
> 
> At 09:51 2003-02-21 -0500, you wrote:
> >I am not sure if this helps, but a forward happens at the 
> server so the 
> >server makes the forwarded request and returns the results to the 
> >browser, so the browser never knows the request has changed and 
> >therefor the URL in the browser will not change, on the other hand a 
> >redirect tells the browser to go get the new page so the browser URL 
> >will update to the new URL.
> >
> >John
> >
> > > -----Original Message----->
> > >
> > > I need help. (I use Tomcat 4.1.18)
> > >
> > > I'm in JSP1 in a webapp (Webapp1) and I use 
> > > RequestDispatcher.forward(request, response) to forward in JSP2 
> > > located in another webapp (Webapp2). The two webapps are 
> on the same 
> > > server. The forwarding works, but once I'm in the JSP2 
> (in Webapp2), 
> > > it looks like I'm
> > > still in the context of Webapp1, the URL of the request
> > > remains the URL of
> > > JSP1 in Webapp1. However, the servlet API documentation
> > > specifically says:
> > >
> > > "For a RequestDispatcher obtained via getRequestDispatcher(), the 
> > > ServletRequest object has its path elements and 
> parameters adjusted 
> > > to match the path of the target resource".
> > >
> > > Here is a simplified part of the code I use in JSP1:
> > >
> > > ServletContext contxt = 
> getServletContext().getContext("/Webapp2");
> > > RequestDispatcher disp = 
> > > contxt.getRequestDispatcher("/JSPinWebapp2.jsp");
> > > disp.forward(request, response);
> > >
> > > Is this a bug, or is there something that I'm missing or not 
> > > understanding about forwarding?
> > >
> > >
> > > Simon Senécal
> > > Lab-Volt Québec (Software Development)
> > > 418-849-1000 #348
> > > http://www.labvolt.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


RequestDispatcher.forward() problem

Posted by Simon Senécal <ss...@labvolt.ca>.
Thanks for your reply, John.

Can you transport data from one webapp to the other when you use the 
sendRedirect() method? Here is my true problem. I want to transport data 
such as a username and a password between two webapps (and I don't want to 
use URL rewriting). The user logs on Webapp1 and after authentification, 
the user has the choice to go to Webapp2, and I need the username and 
password to work in Webapp2. As I understand it, I can't use the session 
object to transport data because each Webapp has it's own session object. 
So I thought of using the forwarding method and use the request object to 
store my data (with setAttribute and getAttribute). It works, but like I 
said in my previous email, after forwarding, I'm still in the context of 
Webapp1.

Simon.

At 09:51 2003-02-21 -0500, you wrote:
>I am not sure if this helps, but a forward happens at the server so the
>server makes the forwarded request and returns the results to the
>browser, so the browser never knows the request has changed and therefor
>the URL in the browser will not change, on the other hand a redirect
>tells the browser to go get the new page so the browser URL will update
>to the new URL.
>
>John
>
> > -----Original Message----->
> >
> > I need help. (I use Tomcat 4.1.18)
> >
> > I'm in JSP1 in a webapp (Webapp1) and I use
> > RequestDispatcher.forward(request, response) to forward in
> > JSP2 located in
> > another webapp (Webapp2). The two webapps are on the same server. The
> > forwarding works, but once I'm in the JSP2 (in Webapp2), it
> > looks like I'm
> > still in the context of Webapp1, the URL of the request
> > remains the URL of
> > JSP1 in Webapp1. However, the servlet API documentation
> > specifically says:
> >
> > "For a RequestDispatcher obtained via getRequestDispatcher(), the
> > ServletRequest object has its path elements and parameters
> > adjusted to
> > match the path of the target resource".
> >
> > Here is a simplified part of the code I use in JSP1:
> >
> > ServletContext contxt = getServletContext().getContext("/Webapp2");
> > RequestDispatcher disp =
> > contxt.getRequestDispatcher("/JSPinWebapp2.jsp");
> > disp.forward(request, response);
> >
> > Is this a bug, or is there something that I'm missing or not
> > understanding
> > about forwarding?
> >
> >
> > Simon Senécal
> > Lab-Volt Québec (Software Development)
> > 418-849-1000 #348
> > http://www.labvolt.com


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


RE: RequestDispatcher.forward() problem

Posted by John Trollinger <ja...@trollingers.com>.
I am not sure if this helps, but a forward happens at the server so the
server makes the forwarded request and returns the results to the
browser, so the browser never knows the request has changed and therefor
the URL in the browser will not change, on the other hand a redirect
tells the browser to go get the new page so the browser URL will update
to the new URL.

John

> -----Original Message-----
> From: Simon Senécal [mailto:ssenecal@labvolt.ca] 
> Sent: Friday, February 21, 2003 9:35 AM
> To: tomcat-dev@jakarta.apache.org
> Subject: RequestDispatcher.forward() problem
> 
> 
> I need help. (I use Tomcat 4.1.18)
> 
> I'm in JSP1 in a webapp (Webapp1) and I use 
> RequestDispatcher.forward(request, response) to forward in 
> JSP2 located in 
> another webapp (Webapp2). The two webapps are on the same server. The 
> forwarding works, but once I'm in the JSP2 (in Webapp2), it 
> looks like I'm 
> still in the context of Webapp1, the URL of the request 
> remains the URL of 
> JSP1 in Webapp1. However, the servlet API documentation 
> specifically says:
> 
> "For a RequestDispatcher obtained via getRequestDispatcher(), the 
> ServletRequest object has its path elements and parameters 
> adjusted to 
> match the path of the target resource".
> 
> Here is a simplified part of the code I use in JSP1:
> 
> ServletContext contxt = getServletContext().getContext("/Webapp2");
> RequestDispatcher disp = 
> contxt.getRequestDispatcher("/JSPinWebapp2.jsp"); 
> disp.forward(request, response);
> 
> Is this a bug, or is there something that I'm missing or not 
> understanding 
> about forwarding?
> 
> 
> Simon Senécal
> Lab-Volt Québec (Software Development)
> 418-849-1000 #348
> http://www.labvolt.com          
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org