Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Best way

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Servlet S1 forwards a request to Servlet S2. The BEST way for Servlet S1 to pass data to Servlet S2 is by saving the data to
a) A Cookie.
b) The request object.
c) The ServletContext.
d) The HttpSession object.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest the answer is b) the request object. This is because it is only valid for the scope of the request.
Storing in the ServletContext could mean that another servlet could over-write the data.
Storing in Cookies makes no sense - these are for passing data to the client.
Storing in a Session would work but it would mean that the data would persist for the duration of the session which is probably not appropriate.
 
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way is allways the way with the least possible side-effects.
So its request. The narrowest scope which can be used to pass the information should normally have the least possible side-effects.
 
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic