jsp

in JSP is there a way to pass HttpServletRequest object as an attribute to another HttpServletRequest object


I am using Struts/JSP for a webapp. I have a page A where I am collecting user defined parameters (as request parameters can't make them session params) and then I go to page B to ask yes/no kind of a question to the user. In case of yes I need to come back to page A and continue regular processing. But obviously the request object for page A is gone.

Is there a way to set page A's request object as parameter in page B so that when I come back to page A i have the same request object I had when i was there (on page A) the first time.

I need something like below:

page A --(req1)------> page B (set req.setAttr('prevReq', req1)) ------> page A (req = req.getAttr('prevReq'))

Any help is appreciated.


Solution

  • No, you can't do what you have in mind. Do you understand how the HTTP request-response cycle works?

    There is no way that you can save the request for page A, and then in page B respond to that request to make the browser go back to page A. That's just not how the request-response cycle works.

    What you can do, is store data in the session object. You can call request.getSession() to get a HttpSession object, in which you can store data for the duration of the session of that user. In page A, you can get the data out of the session object again.