flowcontrol
Programmer
I have a database that uses sequentially numbered primary keys (ID). I developed a bean to hold the next ID for each of several tables. Each servlet that needs to insert a record into a table gets the ID for the record from the bean. The bean is instantiated from within a JSP page (<jsp:useBean ... scope="application"/>).
The bean's properties (the next IDs for several tables) are initialized in the constructor by querying the database. I've got it working perfectly using a hard-coded database driver and connection string. Now, I want to change it to get the database driver and connection string from context-params defined in the deployment descriptor.
The problem I'm having is that I can't figure out how to get the servlet context (from which I can get the context-param). The bean is not a servlet, so it does not have access to a ServletRequest object (from which I could get the context).
How can this bean get a reference to the ServletContext?
The bean's properties (the next IDs for several tables) are initialized in the constructor by querying the database. I've got it working perfectly using a hard-coded database driver and connection string. Now, I want to change it to get the database driver and connection string from context-params defined in the deployment descriptor.
The problem I'm having is that I can't figure out how to get the servlet context (from which I can get the context-param). The bean is not a servlet, so it does not have access to a ServletRequest object (from which I could get the context).
How can this bean get a reference to the ServletContext?