----- Original Message -----
From: Jianhong
Sent: Tuesday, July 27, 1999 11:18 AM
Subject: Cann't read parameter from properties file

Hi, everyone,
 
I want to read DSN and so on from properties file to init a database Connection, but I don't know why what I read is null.
Here is the file "servlets.properties":
 
# $Id: servlets.properties,v 1.2 1999/04/02 02:04:01 duncan Exp $
# Define servlets here
# <servletname>.code=<servletclass>
# <servletname>.initparams=<name=value>,<name=value>
 
#SimpleServlet.code=SimpleServlet
#SimpleServlet.initparams=DSN=iceClassified,UID=sa
cookie.code=CookieExample
cookie.initparams=foo
jsp.code=com.sun.jsp.runtime.JspServlet
Does anyone can help me out?
Thanks in advance.
 
Jianhong
 
Hi Jianhong,
 
are you setting up your servlet init method correctly?
 
That is where the servlet init params are delivered to.
 
it should look something like this
 
// Servlet class declaration omitted for brevity...
 
public void init(ServletConfig config) {
    super.init(config);
    // Now we come to reading your parameters if we can
    // You would need to declare placeholders for these parameters as instance variables....
   
    if(getInitParameter("DSN") != null) {
        dsn = getInitParameter("DSN");
     }
     // Repeat for the other parameters
}
 
It also looks like the init params for your servlet are commented out as well so they will be ignored.
 
Hope that helps
 
Andy Bailey

Reply via email to