You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jason Johnston <Ja...@epa.state.il.us> on 2002/12/17 16:25:20 UTC
Re: JSP to Servlet to JSP pathing issue. Relative Pathing
Please help.
The redirecting doesn't seem to work. That tells the browser client to
initiate a new request and all the
information that I placed in the request object is gone, which
undermines the purpose of the form.
The forums have a lot on my problem, just no answers that have worked
for me. Has anyone else ran into the issue of using a form in a JSP to
submit data to a Servlet, have that servlet return data to the very same
JSP?
Thanks in advance.
>>> Jason.Johnston@epa.state.il.us 12/16/02 12:53PM >>>
Thanks for the advice, I didn't know you could redirect. The javadoc
on
the RequestDispatcher only lists the forward and include methods.
I'll
try that.
The initial call to the servlet is actually being made by the client
browser via a form response.
>>> mike@ward-murphy.co.uk 12/16/02 12:00PM >>>
If you want the path in the browser's address bar to change, I think
you
have to use a "redirect" rather than a "forward". (I've read that
even
then
it's not guaranteed to work (since it's browser-dependent), but it's
working
fine for me. There's the disadvantage of an additional network
round-trip
that's not ideal, but I don't know of any other way.)
[Actually, I guess you're already redirecting from the original jsp
request
to the servlet. If you changed that to "forward" then that'd probably
solve
you're problem without the additional round-trip....]
Mike.
----- Original Message -----
From: "Jason Johnston" <Ja...@epa.state.il.us>
To: "<"Tomcat Users List"" <to...@jakarta.apache.org>
Sent: Monday, December 16, 2002 5:46 PM
Subject: JSP to Servlet to JSP pathing issue. Relative Pathing Please
help.
I have a JSP that has a form that I want processed by a servlet. The
servlet then places the results in the page context and redirects back
to the JSP.
Everything works fine on the first go, but the second time through the
path in the client's browser is no longer valid.
Initially, the path is:
http://localhost:8080/testgroup/lookup.jsp
This then sends the form data to the
/testgroup/servlet/dolookup?<parameters>
The servlet executes and uses the request dispatcher to load the
original JSP.
RequestDispatcher
rd=getServletContext().getRequestDispatcher("//lookup.jsp");
rd.forward(request,response);
The original JSP comes up fine and has the results, but the path in
the
browser URL is still the servlet address. Since the form sends to a
relative path, the second time you try to run, it doesn't work.
http://localhost:8080/testgroup/servlet/test.dolookup?epaid=J2466&search=id&
firstname=&lastname=
This seems to be a very simple relative pathing problem, but I've
tried
various solutions with no luck. I'm sure someone else has run into
this
and found a solution. If anyone has any insight, please help.
Thanks.
--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>
Re: JSP to Servlet to JSP pathing issue. Relative PathingPlease help.
Posted by Anthony Ikeda <ai...@ihug.com.au>.
This is something that many people have problems understanding.
The concept of Forwarding is not to redirect the user to another site but to
forward functionality to another JSP/Servlet.
Forwarding has no client side control or interaction, all your doing is
asking the web container to move the current processes to another class to
continue processing. Therefore the client doesn't know your going elsewhere
to say, save data to a database, store an image, email everyone that this
person is using their website.
Redirecting is a client call to get their web browser to do the work. A web
container cannot load the contents of another location for a client browser
if the client is required to re-locate to another URL. You can read the URL
and stream the data but there is little point in doing so.
A redirect tells the clients browser to go to this new address. Much like
the META tag attribute to refresh, the redirect works the same way.
Therefore if your forwarding, then the servlet you forward to is not a new
location reference as it's now part of the current process. Processing has
been forwarded to the new servlet and become part of the process as a whole.
The same goes for inluding. The only difference is when you include your
prcesses return to the orignal calling class.
Redirection: Tell browser to go elsewhere
Forwarding: Send current processes to another class
Cheers,
Anthony
----- Original Message -----
From: "Jason Johnston" <Ja...@epa.state.il.us>
To: <to...@jakarta.apache.org>
Sent: Wednesday, December 18, 2002 2:25 AM
Subject: Re: JSP to Servlet to JSP pathing issue. Relative PathingPlease
help.
> The redirecting doesn't seem to work. That tells the browser client to
> initiate a new request and all the
> information that I placed in the request object is gone, which
> undermines the purpose of the form.
>
> The forums have a lot on my problem, just no answers that have worked
> for me. Has anyone else ran into the issue of using a form in a JSP to
> submit data to a Servlet, have that servlet return data to the very same
> JSP?
>
> Thanks in advance.
>
>
> >>> Jason.Johnston@epa.state.il.us 12/16/02 12:53PM >>>
> Thanks for the advice, I didn't know you could redirect. The javadoc
> on
> the RequestDispatcher only lists the forward and include methods.
> I'll
> try that.
>
> The initial call to the servlet is actually being made by the client
> browser via a form response.
>
>
> >>> mike@ward-murphy.co.uk 12/16/02 12:00PM >>>
> If you want the path in the browser's address bar to change, I think
> you
> have to use a "redirect" rather than a "forward". (I've read that
> even
> then
> it's not guaranteed to work (since it's browser-dependent), but it's
> working
> fine for me. There's the disadvantage of an additional network
> round-trip
> that's not ideal, but I don't know of any other way.)
> [Actually, I guess you're already redirecting from the original jsp
> request
> to the servlet. If you changed that to "forward" then that'd probably
> solve
> you're problem without the additional round-trip....]
>
> Mike.
>
>
>
> ----- Original Message -----
> From: "Jason Johnston" <Ja...@epa.state.il.us>
> To: "<"Tomcat Users List"" <to...@jakarta.apache.org>
> Sent: Monday, December 16, 2002 5:46 PM
> Subject: JSP to Servlet to JSP pathing issue. Relative Pathing Please
> help.
>
>
> I have a JSP that has a form that I want processed by a servlet. The
> servlet then places the results in the page context and redirects back
> to the JSP.
>
> Everything works fine on the first go, but the second time through the
> path in the client's browser is no longer valid.
>
> Initially, the path is:
>
> http://localhost:8080/testgroup/lookup.jsp
>
> This then sends the form data to the
> /testgroup/servlet/dolookup?<parameters>
>
> The servlet executes and uses the request dispatcher to load the
> original JSP.
>
> RequestDispatcher
> rd=getServletContext().getRequestDispatcher("//lookup.jsp");
> rd.forward(request,response);
>
> The original JSP comes up fine and has the results, but the path in
> the
> browser URL is still the servlet address. Since the form sends to a
> relative path, the second time you try to run, it doesn't work.
>
>
>
http://localhost:8080/testgroup/servlet/test.dolookup?epaid=J2466&search=id&
>
>
> firstname=&lastname=
>
> This seems to be a very simple relative pathing problem, but I've
> tried
> various solutions with no luck. I'm sure someone else has run into
> this
> and found a solution. If anyone has any insight, please help.
>
> Thanks.
>
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: JSP to Servlet to JSP pathing issue. Relative PathingPlease help.
Posted by Mike W-M <mi...@ward-murphy.co.uk>.
True (and I missed that that was the whole point of your exercise) but
redirecting is the (only) way to get the browser's URL to change.
If you think about it, you're basically saying that you want two different
URLs (one to the servlet and one to the jsp), when displayed in the browser,
to mean the same thing - which just isn't going to work.
Two possible solutions:
a) The ugly but quicker one: code the absolute URL in the jsp's form's
action attribute.
b) The elegant one: Don't link to the jsp page at all. Always link to the
servlet, then make the servlet check for the existence of parameters. If
your parameters exist then it was a form submission, so do what ever you do
now and then forward() to the jsp. (This leaves the URL the same in the
browser and doesn't lose the request-info.) If parameters don't exist, then
just forward() to the jsp page (without doing any processing). It'll
presumably behave like it does now when you request it directly. However,
the browser's URL will still have the servlet's URL - and you can code all
the paths relative to that.
Mike.
----- Original Message -----
From: "Jason Johnston" <Ja...@epa.state.il.us>
To: <to...@jakarta.apache.org>
Sent: Tuesday, December 17, 2002 3:25 PM
Subject: Re: JSP to Servlet to JSP pathing issue. Relative PathingPlease
help.
The redirecting doesn't seem to work. That tells the browser client to
initiate a new request and all the
information that I placed in the request object is gone, which
undermines the purpose of the form.
The forums have a lot on my problem, just no answers that have worked
for me. Has anyone else ran into the issue of using a form in a JSP to
submit data to a Servlet, have that servlet return data to the very same
JSP?
Thanks in advance.
>>> Jason.Johnston@epa.state.il.us 12/16/02 12:53PM >>>
Thanks for the advice, I didn't know you could redirect. The javadoc
on
the RequestDispatcher only lists the forward and include methods.
I'll
try that.
The initial call to the servlet is actually being made by the client
browser via a form response.
>>> mike@ward-murphy.co.uk 12/16/02 12:00PM >>>
If you want the path in the browser's address bar to change, I think
you
have to use a "redirect" rather than a "forward". (I've read that
even
then
it's not guaranteed to work (since it's browser-dependent), but it's
working
fine for me. There's the disadvantage of an additional network
round-trip
that's not ideal, but I don't know of any other way.)
[Actually, I guess you're already redirecting from the original jsp
request
to the servlet. If you changed that to "forward" then that'd probably
solve
you're problem without the additional round-trip....]
Mike.
----- Original Message -----
From: "Jason Johnston" <Ja...@epa.state.il.us>
To: "<"Tomcat Users List"" <to...@jakarta.apache.org>
Sent: Monday, December 16, 2002 5:46 PM
Subject: JSP to Servlet to JSP pathing issue. Relative Pathing Please
help.
I have a JSP that has a form that I want processed by a servlet. The
servlet then places the results in the page context and redirects back
to the JSP.
Everything works fine on the first go, but the second time through the
path in the client's browser is no longer valid.
Initially, the path is:
http://localhost:8080/testgroup/lookup.jsp
This then sends the form data to the
/testgroup/servlet/dolookup?<parameters>
The servlet executes and uses the request dispatcher to load the
original JSP.
RequestDispatcher
rd=getServletContext().getRequestDispatcher("//lookup.jsp");
rd.forward(request,response);
The original JSP comes up fine and has the results, but the path in
the
browser URL is still the servlet address. Since the form sends to a
relative path, the second time you try to run, it doesn't work.
http://localhost:8080/testgroup/servlet/test.dolookup?epaid=J2466&search=id&
firstname=&lastname=
This seems to be a very simple relative pathing problem, but I've
tried
various solutions with no luck. I'm sure someone else has run into
this
and found a solution. If anyone has any insight, please help.
Thanks.
--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>