This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
The moose likes Servlets and the fly likes Confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Confusion" Watch "Confusion" New topic


Anu Pasricha

Joined: Jul 08, 2002
Posts: 13
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?
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13028
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.
I agree. Here's the link:
subject: Confusion
It's not a secret anymore!