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

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

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who said anything about a static class?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could pass a reference to the context in the PokerFacade constructor, or add a setter for it.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter Primrose:

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

anyone?


Then you cannot access the object bound to servletContext
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic