You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by James Michelich <jr...@duke.edu> on 2003/08/12 22:50:14 UTC

Forwarding control

Hello, any help would be much appreciated.

The basic scenario is as follows - I have a form page called form.jsp 
(http://localhost/webapp/form.jsp).  Upon submission, the form data is 
processed by a servlet mapped to the url '/process' 
(http://localhost/webapp/process).  Once the servlet has completed 
processing the form data, it forwards control to a results page 
(http://localhost/webapp/result.jsp) via

    RequestDispatcher dispatch = request.getRequestDispatcher
(forwardPath);
    dispatch.forward(request, response);

My question is this - although control has been forwarded to the 
results page, the browser's url is still 
http://localhost/webapp/process, which is ok with me; however, if the 
page is refreshed, the browser prompts for the form data to be 
resubmitted and the processing is repeated (which for my application 
happens to be quite substantial), rather than refreshing the contents 
of the results page.

I suppose this is a minor annoyance that could be worked around by 
displaying a link to the results page rather than forwarding directly 
to it, but I'd rather implement the latter.

Does anyone know of a solution or workaround for this problem?

Thanks in advance,

James


RE: Forwarding control

Posted by "Mike Cherichetti (Renegade Internet)" <mi...@renegadeinternet.com>.
James,

Use response.sendRedirect() instead of the RequestDispatcher.  That will
change the URL in the browser.  If you want to stick with the
RequestDispatcher, you'll have to add some logic to catch a resubmission of
the same data (possibly use a hidden field in your forms with a unique
identifier, random number, timestamp, etc... and record those in the user
session or a backend database) and skip over processing and go straight to
the result.jsp.

Hope that helps.

Mike


-----Original Message-----
From: James Michelich [mailto:jrm8@duke.edu]
Sent: Tuesday, August 12, 2003 4:50 PM
To: tomcat-user@jakarta.apache.org
Subject: Forwarding control


Hello, any help would be much appreciated.

The basic scenario is as follows - I have a form page called form.jsp
(http://localhost/webapp/form.jsp).  Upon submission, the form data is
processed by a servlet mapped to the url '/process'
(http://localhost/webapp/process).  Once the servlet has completed
processing the form data, it forwards control to a results page
(http://localhost/webapp/result.jsp) via

    RequestDispatcher dispatch = request.getRequestDispatcher
(forwardPath);
    dispatch.forward(request, response);

My question is this - although control has been forwarded to the
results page, the browser's url is still
http://localhost/webapp/process, which is ok with me; however, if the
page is refreshed, the browser prompts for the form data to be
resubmitted and the processing is repeated (which for my application
happens to be quite substantial), rather than refreshing the contents
of the results page.

I suppose this is a minor annoyance that could be worked around by
displaying a link to the results page rather than forwarding directly
to it, but I'd rather implement the latter.

Does anyone know of a solution or workaround for this problem?

Thanks in advance,

James


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






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


RE: Forwarding control

Posted by "Mike Cherichetti (Renegade Internet)" <mi...@renegadeinternet.com>.
James,

Use response.sendRedirect() instead of the RequestDispatcher.  That will
change the URL in the browser.  If you want to stick with the
RequestDispatcher, you'll have to add some logic to catch a resubmission of
the same data (possibly use a hidden field in your forms with a unique
identifier, random number, timestamp, etc... and record those in the user
session or a backend database) and skip over processing and go straight to
the result.jsp.

Hope that helps.

Mike


-----Original Message-----
From: James Michelich [mailto:jrm8@duke.edu]
Sent: Tuesday, August 12, 2003 4:50 PM
To: tomcat-user@jakarta.apache.org
Subject: Forwarding control


Hello, any help would be much appreciated.

The basic scenario is as follows - I have a form page called form.jsp
(http://localhost/webapp/form.jsp).  Upon submission, the form data is
processed by a servlet mapped to the url '/process'
(http://localhost/webapp/process).  Once the servlet has completed
processing the form data, it forwards control to a results page
(http://localhost/webapp/result.jsp) via

    RequestDispatcher dispatch = request.getRequestDispatcher
(forwardPath);
    dispatch.forward(request, response);

My question is this - although control has been forwarded to the
results page, the browser's url is still
http://localhost/webapp/process, which is ok with me; however, if the
page is refreshed, the browser prompts for the form data to be
resubmitted and the processing is repeated (which for my application
happens to be quite substantial), rather than refreshing the contents
of the results page.

I suppose this is a minor annoyance that could be worked around by
displaying a link to the results page rather than forwarding directly
to it, but I'd rather implement the latter.

Does anyone know of a solution or workaround for this problem?

Thanks in advance,

James


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