This week's book giveaway is in the Agile forum.
We're giving away four copies of The Software Craftsman and have Sandro Mancuso on-line!
See this thread for details.
The moose likes Servlets and the fly likes Accessing Servlet Context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Accessing Servlet Context " Watch "Accessing Servlet Context " New topic

Accessing Servlet Context

Ratheesh Narayanan
Ranch Hand

Joined: Oct 30, 2004
Posts: 38

How costly is it, to retrive a string data from ServletContext on every request?

I have a RequestListener which will retrive two string values from a ServletContext on every request and data in these strings will be same across all the requests, it doesn't change. What would you suggest? Write a raw code to fetch out the strings on every request or a wrapper data object which maintain the strings once its initialized?

Thanks in advance!

SCJP 1.4 & SCBCD 1.5
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42954
Is there any particular reason you can't store the values in static fields in the listener object?
Ratheesh Narayanan
Ranch Hand

Joined: Oct 30, 2004
Posts: 38
Yes, it's a good decision!

Even I was thinking of maintaining this in a static field, but it was not primary solution for me, till I see your reply. You made me to re-think.

Thanks a lot!
Have you tried LearnNowOnline?
subject: Accessing Servlet Context