Ok, then I must be having another problem. I'm running into a null pointer exception
that I was assuming was the Tag's inability to retrieve a handle on the pool.
Here's my code:
/*
* testTag.java
*
* Created on September 23, 2002, 3:21 PM
*/
package boa;
import sun.misc.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
import com.javaexchange.dbConnectionBroker.*;
/**
*
* @author epa2466
* @version
*/
public class testTag extends BodyTagSupport {
/** Creates new testTag */
public int doStartTag() throws JspException {
JspWriter out = pageContext.getOut();
DbConnectionBroker
pool=(DbConnectionBroker)pageContext.getServletContext().getAttribute("dbPool");
if(pool==null){
try{
out.println("Couldn't find Pool");
return SKIP_BODY;
}catch(IOException e){};
}else{
Connection conn=pool.getConnection();
try{
if(conn==null)
{
//out.println("No Connection available");
}
else
{
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from names");
out.println("<table>");
while(rs.next()){
out.println("<tr><td>"
+ rs.getString("FirstName")
+ "</td><td>"
+ rs.getString("LastName")
+ "</td></tr>");
}
out.println("</table>");
}
//out.println("</html>");
}catch(SQLException e){throw new JspTagException("SQL Exception");}
catch(IOException e2){throw new JspTagException("I/O Exception");}
}
return SKIP_BODY;
}
}
The error I'm getting is:
java.lang.NullPointerException
at boa.testTag.doStartTag(testTag.java:28)
at org.apache.jsp.bob$jsp._jspService(bob$jsp.java:67)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
.
.
.
.
Line 28 of testTag is the line
DbConnectionBroker
pool=(DbConnectionBroker)pageContext.getServletContext().getAttribute("dbPool");
If anyone has any insight, I would appreciate it. Thanks
>>> [EMAIL PROTECTED] 09/24/02 11:48AM >>>
The following will work:
pageContext.getServletContext().getAttribute("dbPool");
-----Original Message-----
From: Jason Johnston [mailto:[EMAIL PROTECTED]]
Sent: 24 September 2002 17:25
To: <"Tomcat Users List"
Subject: Retrieving ServletContext Objects via PageContext
This may be a stupid question but I'm just starting to use custom tags and
I'm running into a strange problem. I'm using a DBCP for a mySQL database
and my setup servlet places a handle to the pool in the ServletContext via
the setAttribute() under the name "dbPool."
Now other servlets can retrieve the pool handle fine and get a connection
and do their business. However my tag, which extends TagSupport can't seem
to find the pool. Initially, I used
getServletContext.getAttribute("dbPool"). Of course, I got a compile error
telling me that there is no such method.
After some reading, it appeared that what I'm looking for should be
available via
the pageContext.getAttribute("dbPool",pageContext.APPLICATION_SCOPE);
However, I'm still not getting a handle on the DB Pool. I know there's
probably somethings fairly simple I'm missing here, either syntax or
concept. Could someone give me some insight. Thanks.
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>