Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request

 
Chris-Huisman
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think so. As long as you use forward(request, response) the request object will be passed all the way down.
 
Stu Glassman
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mario Rendon
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic