This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confusion

 
Anu Pasricha
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
When it is possible to access pakage level variables in the same package by other classes, then why do servlets communicate via query strings, session variables, hidden fields etc.
Why don't we make a class containing required variables, give it package level accessibility and set & use their values in servlets where-ever required?
Regards
Anu
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keep in mind that the main problem with servlets is managing user data so it doesn't get mixed up with other "simultaneous" users. The very elegant servlet API uses sessions for this. It is indeed a good idea to create a class to hold user specific variables. This can be shared between servlets by the session mechanism or whatever you like.
Bill
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic