File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "request " Watch "request " New topic
Author

request

Chris-Huisman
Greenhorn

Joined: Jan 25, 2002
Posts: 23
I am wondering exactly how long a request object lasts for. I am submitting some form data to a servlet. In certain instances the servlet forwards the request to a different servlet, which then goes to another jsp using :
request.getRequestDispatcher("/servlet").forward(request, response);
Do I still have access to all of the request objects parameters/attributes in the second servlet? And if so, can you forward to n servlets and still keep a hold of the request parameters/attributes?
thanks,
C.
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 671
I think so. As long as you use forward(request, response) the request object will be passed all the way down.


BJ - SCJP and SCWCD
We love Java programming. It is contagious, very cool, and lot of fun. - Peter Coad, Java Design

Crazy Bikes created by m-Power
Stu Glassman
Ranch Hand

Joined: Jul 01, 2002
Posts: 91
You definitely can, but I wouldn't suggest it. If you want to keep data "alive" for the invocation of several different servlets, try storing the data in a session.
-Stu
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Stu Glassman:
You definitely can, but I wouldn't suggest it. If you want to keep data "alive" for the invocation of several different servlets, try storing the data in a session.
-Stu


Stu, I would like to know why would you prefer storing information into the session instead of the request object? Of course it's the right way to go if the data shall be alive for multiple requests, but if the data needs to live just long enough for the final output (html) to be generated, why use the session?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Mario Rendon
Greenhorn

Joined: Jul 11, 2002
Posts: 24
Servlet's allows to fonward and include output from other servlets and even JSP in the same context ..
and eventually if you want to make a well role defined model .. you can make the controller logic on servlet and rely on other servlets or maybe on a JSPs to manage the response given to the user ..
Mario Rendon
Greenhorn

Joined: Jul 11, 2002
Posts: 24
Originally posted by Lasse Koskela:


Stu, I would like to know why would you prefer storing information into the session instead of the request object? Of course it's the right way to go if the data shall be alive for multiple requests, but if the data needs to live just long enough for the final output (html) to be generated, why use the session?

completelly agree with Lasse the requst information shoud keept on request/response scope.. if you mix such information to Session level you pobably would have some problems with other request on the same session .
remeber even that even session means one user.. it doesn't mean a single thread nor a single concurrent request.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: request