Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

getting the initial parameters for servlet

843841Oct 24 2004 — edited Oct 27 2004
Hello

I'm trying to get the initial parameters for my servlet. I have changed the ../conf/web.xml from my Tomcat in the sense that I added this:
<!-- Init parameters for the servlet DatabaseServlet -->
  <servlet>
    <servlet-name>DatabaseServlet</servlet-name>
    <servlet-class>server.DatabaseServlet</servlet-class>
        <init-param>
            <param-name>database</param-name>
            <param-value>Test</param-value>
        </init-param>
        <init-param>
            <param-name>user</param-name>
            <param-value>sa</param-value>
        </init-param>
        <init-param>
            <param-name>password</param-name>
            <param-value></param-value>
        </init-param>
  </servlet>
right before the 'Build in Servlet Mappings'.
In the doGet method I have added:
String dbase= getServletConfig().getInitParameter("database");
String duser= getServletConfig().getInitParameter("user");
String dpassword= getServletConfig().getInitParameter("password");
but al this values are null and I don't know why.

The servlet class is in ROOT/WEB-INF/classes/server. I have no password for my server, so I use only 'sa' for loging in.
I've tried using the init method like this:
  String dbase= null;
  String duser= null;
  String dpassword= null;
  public void init(ServletConfig config) throws ServletException {
    super.init(config);	

    dbase= config.getInitParameter("database");
    duser= config.getInitParameter("user");
    dpassword= config.getInitParameter("password");
  }
but I get the same error: "Log in failed for user 'duser'" and that is because all my parameters are 'null'.
All works just fine if I don't use the init parameters and put the values direct in the code.

Please help.

Regards,
Michael
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 24 2004
Added on Oct 24 2004
11 comments
274 views