|
Hello Brad,
You wrote:
>The only thing that still boggles my mind is what sets the default path
>where the program will look for these files? Is it one path, or is it the
>entire classpath?
The old "Chicken and Egg" problem! Where do I look first? You can configure
the servlet to receive initial parameters passed in by WebSphere. One of
these could be the location of the properties file. What I've done in the
past is:
1/ Configure WebSphere to pass initial parameters. For WebSphere 2.x
this is done by editing
/QIBM/PRODdata/IBMWebAS/properties/server/servlet/servletservice/servlets.pro
perties
Add the following lines to the bottom of the file after the comment
#Servlets added by the user
#Link2parts configuration information
servlet.ServletName.code=ServletName
servlet.ServletName.initArgs=cfgfile=/MyStuff/ProdData/Servlets/MyStuff.servl
et.properties
(replacing ServletName with your servlet name)
2/ Receive those parameters: in the init() method if they are fairly
static or in the doPost() or doGet() methods if you want any property changes
to be immediately reflected.
Here is an example method to determine the name of the properties file,
create a Properties object from the contents of that file, and return the
Properties object to the caller.
/**
* This method was created in VisualAge.
* @return java.util.Properties
* @exception javax.servlet.ServletException The exception description.
*/
private Properties getMyStuffProperties() throws ServletException
{
Properties myStuffProperties = new Properties();
// Get the location of the MyStuff configuration file
String cfgFilePath = getInitParameter(MyStuffConstants.INIT_PARM_CFGFILE);
// Create an input reader for the configuration file
try
{
FileInputStream cfgFile = new FileInputStream(cfgFilePath);
// Load a properties object from the file contents
try
{
myStuffProperties.load(cfgFile);
return new Properties(myStuffProperties);
}
catch (IOException theException)
{
getServletContext().log(theException, "Errors occurred loading the
configuration file:" + cfgFilePath);
throw new UnavailableException(this, theException.toString());
}
}
catch (FileNotFoundException theException)
{
getServletContext().log(theException, "Errors occurred opening the
configuration file:" + cfgFilePath);
throw new UnavailableExceptio
this, theException.toString());
}
}
3/ Use those parameter values as necessary in the code. For example:
// Create JDBC connection specification.
connSpec = new IBMJdbcConnSpec(myStuffProperties.getProperty("POOL_NAME"),
true,
myStuffProperties.getProperty("JDBC_URL"),
myStuffProperties.getProperty("DB_URL"),
myStuffProperties.getProperty("USER_ID"),
myStuffProperties.getProperty("PWD"));
4/ Provide an "administration" web page (via servlet and JSP) that
allows the properties to be maintained. Use HTTP server protection
mechanisms to restrict access to the configuration servlet.
The properties file can contain anything you desire. For example:
#MyStuff configuration file
#Sat Apr 29 04:07:08 GMT+00:00 2000
JDBC_URL=com.ibm.db2.jdbc.app.DB2Driver
DB_URL=jdbc:db2:*LOCAL
POOL_NAME=JdbcDb2
USER_ID=PLEBIAN
PWD=*******
CONFPWD=*******
DB_LOC=DATA
PROD_LOC=PARTS
STG_TBL_HDR=LORDHD
STG_TBL_DTL=LORDDT
Regards,
Simon Coulter.
«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
«» FlyByNight Software AS/400 Technical Specialists «»
«» Eclipse the competition - run your business on an IBM AS/400. «»
«» «»
«» Phone: +61 3 9419 0175 Mobile: +61 0411 091 400 «»
«» Fax: +61 3 9419 0175 mailto: shc@flybynight.com.au «»
«» «»
«» Windoze should not be open at Warp speed. «»
«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.