aspose file tools*
The moose likes Servlets and the fly likes Application Session and global variable, either static or hashtable object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Application Session and global variable, either static or hashtable object" Watch "Application Session and global variable, either static or hashtable object" New topic
Author

Application Session and global variable, either static or hashtable object

Tim Resh
Greenhorn

Joined: Aug 09, 2006
Posts: 19
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
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

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

Joined: Jan 10, 2002
Posts: 61424
    
  67

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.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Application Session and global variable, either static or hashtable object