On Fri, 9 Mar 2001 [EMAIL PROTECTED] wrote:

> Hi,
> 
> I have been unable to get at the servletcontext param values.  I keep
> getting the null pointer exception.
> I have looked thru all the archives and quite a few sites trying all the
> recommendations, but to no avail.
> Must be doing something really stupid, or I've missed a basic concept
> somewhere.
> I am running tomcat 3.2.1
> 
> Any hints would be gratefully appreciated.
> Thanks in advance.
> Chuck

What URL are you using to access the servlet?  Where (in the directory
structure) is your servlet class located?


> Here's my web.xml and the code trying to get at it.
> 
> <web-app>
>     <display-name>jdbctut</display-name>
>     <description>This is version X.X of an application to
> perform</description>
>     <context-param>
>       <param-name>dbuser</param-name>
>       <param-value>fabdev</param-value>
>       <description>User name to logon to the Db.</description>
>     </context-param>
>     <servlet>
>       <servlet-name>DataBaseSelect</servlet-name>
>       <description> This servlet </description>
>       <servlet-class>DataBaseSelect</servlet-class>
>       <!-- Load this servlet at server startup time -->
>       <load-on-startup>5</load-on-startup>
>     </servlet>
>     <servlet-mapping>
>       <servlet-name>DataBaseSelect</servlet-name>
>       <url-pattern>jdbctut</url-pattern>
>     </servlet-mapping>
>     <session-config>
>       <session-timeout>30</session-timeout>    <!-- 30 minutes -->
>     </session-config>
> </web-app>
> 
> import java.sql.*;
> import java.util.Vector;
> import javax.servlet.http.*;
> import javax.servlet.*;
> import java.io.*;
> public class DataBaseSelect extends HttpServlet {
>    
>    private Vector result;
>    private String url =
> "jdbc:informix-sqli://poldev:2005/fabdev:INFORMIXSERVER=poldev_713_tcp";
> 
>   public void init( ServletConfig config ) throws
> javax.servlet.ServletException{
>      super.init( config ) ; // Essential!!
>   }
>      
>    public DataBaseSelect() {
>       result = new Vector();
>    } // constructor DataBaseSelect
>    
>    public String connect() {
>       try {
>        Class.forName("com.informix.jdbc.IfxDriver").newInstance();
>        return "Driver Loaded!";
>       } catch (Exception E) {
>        return "Unable to load driver.";
>       }
>    }
>    
>    public String select() {
> //    String value = getServletContext().getInitParameter("dbuser");
> //
> System.out.println(getServletConfig().getServletContext().getInitParameter("
> dbuser"));
>       ServletConfig sc = getServletConfig(); 
>             ServletContext sctx = sc.getServletContext();
>       System.out.println(sctx.getInitParameter("dbuser"));
> 
>       try {
>        Connection C = DriverManager.getConnection(url, "fabdev",
> "fabdev$");
>        Statement Stmt = C.createStatement();
>        ResultSet myResult = Stmt.executeQuery("SELECT lst_nm from
> person_profile ORDER BY lst_nm");
>        
>        while (myResult.next()) {
>           result.addElement(myResult.getString(1));
>        }
>        
>          // Clean up
>          myResult.close();
>          Stmt.close();
>          C.close();
>        return "Connection Success!";
>       } catch (SQLException E) {
>               return "SQLException: " + E.getMessage();
>       }
>    }
>       
>    /**
>     * Accessor for result
>     **/
>    public Vector getResult() {
>       return result;
>    }
>    
>    /**
>     * Mutator for result
>     **/
>    public void setResult(Vector avector) {
>      result = avector;
>    }  
>    
> } // class DataBaseSelect
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Sure there's apathy in the world.
> But who cares.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, email: [EMAIL PROTECTED]
> 

Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to