This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Application Session and global variable, either static or hashtable object

 
Tim Resh
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a hard time understanding the servlet memory/object management.

Ex.


now when the end user goes to a url that calls a actionGeneric.preprocess Class which in turns forwards to a login.jsp

Everything works fine and user gets login page,
he then enters login and submits, which causes a actionGeneric.postprocess to be called passing the form to it.

In the actionGeneric.postprocess we check the database for login authority like this:



So far so good, everthing works.

In user.checklogin Class I use a helper class DBAcessor to get the table rows and columns




Here is where the problem is

in DBaccessor I need access to the properties I loaded in the servlet config file that went into the hashtable with key ("props")

to retrieve DB settings for the jdbc connection and other properties I loaded in there. So in the DBaccessor class I have a method :[/b]





SO THE REAL QUESTION IS HOW TO ACCESS THE appMemory static variable created in the MyServlet. It is not visible in the DBAcessor and I do not have a handle on the MyServlet here.

Look at the "Properties properties=loadProperties();" code line in the above segment.

How do I get access to the servlet that is running from the DBAccessor?

What am I missing?


Thanks
Mark









 
Paul Clapham
Sheriff
Posts: 21141
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's nothing special about how objects work in servlets, they work exactly the same way that they work in Java code in general.

By the way I found your post hard to read so I gave up on trying to do that. There's a Code button at the top of the box where you post, and if you use that then your code can be formatted like code. That in turn means you don't need to make everything else bold. So if you could edit your post and do that, I'm sure people would be more likely to pay better attention to it.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64978
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want people to read your posts, you need to make them readable. Use bold sparingly. All bold is as hard to read as all-caps, which should also be avoided. And use code tags for code; read this for more information.

You can go back and change your post to add code tags and remove the bold by clicking the button on your post.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic