Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Application global variables

Status
Not open for further replies.

chrisw09

IS-IT--Management
Nov 23, 2005
22
US
I am working on a website that uses a database. I'd like to have the database variables stored somewhere that my classes, jsp pages and action servlets (struts) will be able to access. Currently I have the variables in an interface and am accessing it with my classes but cannot then with jsp pages.

I thought about storing the data in a flat file then having a class be the reader but didn't think that would be very good since everytime a page loads the file would be accessed.

I'm trying to get to the point where an end-user can make changes to the variables without the need for a compile.

Hope i'm making sense out of this.

thanks
 
Makes sense.

So sounds like these variables are CONSTANTS.

What you can do is create a global properties class (could be a hash map) and call this from your code OR load these constants at run time into the app level variable. Then write a proxy class for this so that your code calls the proxy class and not directly against the application object.

I would suggest the latter.


 
What turns to be called application configuration.

Cheers,
Dian
 
since everytime a page loads the file would be accessed

You should probably be using a Database Connection Pool instead of going to the database direct for connections, anyway. Your database connection parameters would be made available to the connection pool and your pages would just ask the connection pooling software for a connection.

Have a look at or
Tim
 
I guess i should have explained a little further, I wish it was as simple as using a connection pool. I'm connecting to a backend system with a set of classes provided to me to expose business logic (ex: get a product price). There are connection settings that the api uses and would be different if the server name or username were to change. I am able to connect to the database (PROGRESS) directly but I then cannot use the already exisiting application logic.


h0h0h0 you lost me when you said:
load these constants at run time into the app level variable
Are you suggesting that i set the values when the tomcat server starts? If so how then would i access?
 
Of course,

These default constants will be in some XML/PROPERTIES file. Load them into a global object and then get/set them as necessary. Make sure that you always go to the global object for parameters when needed instead of caching them in other objects.

I'm not super familiar with app server configuration but I do know that app servers typically have this sort of functionality as well.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top