This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes how to access the servlet's context in a different file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to access the servlet Watch "how to access the servlet New topic
Author

how to access the servlet's context in a different file?

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Hi guys,

In my startup manger class I'm loading some important information in which I would like to use later.

Say I have just loaded some information from a file "fileInformation"
and I would like to access this information in the application.

I did this:


How can I refer to the fileInfo when I'm in a different class?
say:



obviously, i don't have access to the servletContext?

anyone?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

You'd handle this just as you would in any other Java application. When one object has info that another object needs, the data needs to be passed to the other object.
[ December 08, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
ok, so one way to do that is to pass it to a static class (maybe build a HashMap and store it) but I wonder if there's any way to access the servletContext?

thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Who said anything about a static class?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41182
    
  45
You could pass a reference to the context in the PokerFacade constructor, or add a setter for it.


Ping & DNS - my free Android networking tools app
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by Peter Primrose:

obviously, i don't have access to the servletContext?

anyone?


Then you cannot access the object bound to servletContext


Rahul Bhattacharjee
LinkedIn - Blog
 
Don't get me started about those stupid light bulbs.
 
subject: how to access the servlet's context in a different file?
 
Similar Threads
FileUpload with Orion Package
Gracefully handling IOException: too many open files
The ULTIMATE! From the creator of FileMonitor comes DirectoryMonitor :)
I wrote my own FileMonitor. Check it out.
Sorting Field Order?