You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Rutledge, Aaron" <AR...@5prime.com> on 2002/07/24 23:04:52 UTC

Multiple HttpServletRequest objects

Is it possible to have more than one HttpServletRequest object per
session?  I am trying to store a request from one form as a session
object, process an intermediary form, and then pass the original request
to a servlet.  I have a couple clunky ways of doing this (having the
servlet write a hidden form from the request object and passing this
along).  I tried to create a session object like...
    
protected void doPost(HttpServletRequest request, HttpServletResponse
response)
    throws ServletException, java.io.IOException {    
                HttpSession session = request.getSession();
                session.setAttribute("form_data", request);

...and test the original value with...

protected void doGet(HttpServletRequest request, HttpServletResponse
response)
    throws ServletException, java.io.IOException {    
                HttpSession session = request.getSession();
                HttpServletRequest old_form =
(HttpServletRequest)session.getAttribute("form_data");
		    String a_field = old_form.getParameter("textfield");

to see if I get the original field value for the form field called
"textfield", but I get a null value.  Does anyone have any clever ways
of storing a request object and then submitting later in the session?

Best regards to all!
Aaron

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Multiple HttpServletRequest objects

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 24 Jul 2002, Rutledge, Aaron wrote:

> Date: Wed, 24 Jul 2002 15:04:52 -0600
> From: "Rutledge, Aaron" <AR...@5prime.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: "Tomcat Users List (E-mail)" <to...@jakarta.apache.org>
> Subject: Multiple HttpServletRequest objects
>
> Is it possible to have more than one HttpServletRequest object per
> session?  I am trying to store a request from one form as a session
> object, process an intermediary form, and then pass the original request
> to a servlet.  I have a couple clunky ways of doing this (having the
> servlet write a hidden form from the request object and passing this
> along).  I tried to create a session object like...
>
> protected void doPost(HttpServletRequest request, HttpServletResponse
> response)
>     throws ServletException, java.io.IOException {
>                 HttpSession session = request.getSession();
>                 session.setAttribute("form_data", request);
>
> ...and test the original value with...
>
> protected void doGet(HttpServletRequest request, HttpServletResponse
> response)
>     throws ServletException, java.io.IOException {
>                 HttpSession session = request.getSession();
>                 HttpServletRequest old_form =
> (HttpServletRequest)session.getAttribute("form_data");
> 		    String a_field = old_form.getParameter("textfield");
>
> to see if I get the original field value for the form field called
> "textfield", but I get a null value.  Does anyone have any clever ways
> of storing a request object and then submitting later in the session?
>

It is not legal to maintain a reference to a request after that request
has been completed.

My advice is to look at your problem completely differently -- plan on
pulling out of any request whatever you need to save, and save *that* data
as session attributes.  Trying to save the requests themselves will lead
you to design an application full of spaghetti code, because you'll try to
make everything look like a servlet that processes requests.

It would also be worth your time investigating how Model-View-Controller
(MVC) application frameworks like Struts
<http://jakarta.apache.org/struts> encourage you to architect web
applications.

> Best regards to all!
> Aaron
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Multiple HttpServletRequest objects

Posted by Mike Jackson <mj...@cdi-hq.com>.
The answer about HttpServletRequest objects is probably no, but
it sounds like you need a java bean.  Use the bean to store your
form data (one bean per form might be the cleanest).  Then once
you've validated all the input from all the forms you can do
whatever it is you're attempting to do.

--mikej
-=-----
mike jackson
mjackson@cdi-hq.com

-----Original Message-----
From: Rutledge, Aaron [mailto:ARutledge@5prime.com]
Sent: Wednesday, July 24, 2002 2:05 PM
To: Tomcat Users List (E-mail)
Subject: Multiple HttpServletRequest objects


Is it possible to have more than one HttpServletRequest object per
session?  I am trying to store a request from one form as a session
object, process an intermediary form, and then pass the original request
to a servlet.  I have a couple clunky ways of doing this (having the
servlet write a hidden form from the request object and passing this
along).  I tried to create a session object like...

protected void doPost(HttpServletRequest request, HttpServletResponse
response)
    throws ServletException, java.io.IOException {
                HttpSession session = request.getSession();
                session.setAttribute("form_data", request);

...and test the original value with...

protected void doGet(HttpServletRequest request, HttpServletResponse
response)
    throws ServletException, java.io.IOException {
                HttpSession session = request.getSession();
                HttpServletRequest old_form =
(HttpServletRequest)session.getAttribute("form_data");
		    String a_field = old_form.getParameter("textfield");

to see if I get the original field value for the form field called
"textfield", but I get a null value.  Does anyone have any clever ways
of storing a request object and then submitting later in the session?

Best regards to all!
Aaron

--
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>