Yup, the jsp is in webapps/jdbctut/jdbctut.jsp
This is where i get the err.
if i use this stmt.
==> String value = getServletContext().getInitParameter("dbuser");
or if i use this stmt
==>
System.out.println(getServletConfig().getServletContext().getInitParameter
or if i use these stmts
ServletConfig sc = getServletConfig();
==> ServletContext sctx = sc.getServletContext();
System.out.println(sctx.getInitParameter("dbuser"));
These are the credible methods that I found in various examples and
recomendations,
and these are the stack traces that come back.
javax.servlet.ServletException
at
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImp
l.java:459)
at
_0002fjdbctut_0002ejspjdbctut_jsp_0._jspService(_0002fjdbctut_0002ejspjdbctu
t_jsp_0.java:134)
at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.ja
va:177)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
at org.apache.tomcat.core.Handler.service(Handler.java:286)
at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
7)
at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java:210)
at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)
Root cause:
java.lang.NullPointerException
at DataBaseSelect.select(DataBaseSelect.java:53)
at
_0002fjdbctut_0002ejspjdbctut_jsp_0._jspService(_0002fjdbctut_0002ejspjdbctu
t_jsp_0.java:92)
at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.ja
va:177)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
at org.apache.tomcat.core.Handler.service(Handler.java:286)
at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
7)
at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java:210)
at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)
> -----Original Message-----
> From: Milt Epstein [SMTP:[EMAIL PROTECTED]]
> Sent: Tuesday, March 13, 2001 2:23 PM
> To: [EMAIL PROTECTED]
> Subject: RE: getServletContext null pointer exception
>
> On Tue, 13 Mar 2001 [EMAIL PROTECTED] wrote:
>
> > Thanks for your reply,
> >
> > This is the URL I am using
> http://localhost:8080/jdbctut/jdbctut.jsp
> >
> > The class file is going into the webapps/jdbctut/Web-inf/classes of
> the
> > standard tom-cat installation.
> [ ... ]
>
> Hmmm. I didn't realize you were using a JSP. But since this is
> context-param's we're talking about, I don't think it should matter
> (how you set up init-param's varies slightly for servlets and JSPs).
>
> Where is the JSP file located? webapps/jdbctut/jdbctut.jsp?
>
> Can you give more info about what the problem is, what error you are
> getting? You say you are getting a null pointer exception. What does
> the stack trace look like on that? Does it indicate where the
> exception occurs (i.e. what line)? You might need to turn off the
> compiler to see the line numbers.
>
>
> > > -----Original Message-----
> > > From: Milt Epstein [SMTP:[EMAIL PROTECTED]]
> > > Sent: Saturday, March 10, 2001 9:26 AM
> > > To: [EMAIL PROTECTED]
> > > Subject: Re: getServletContext null pointer exception
> > >
> > > 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]
> >
> > ---------------------------------------------------------------------
> > 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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]