Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Servlet Compile Error (NullPointerException)

0 views
Skip to first unread message

lazlo fruvous

unread,
Jul 7, 2002, 7:53:15 PM7/7/02
to
I am getting this message when I try to compile using "jasper jspc" on
a servlet that i basically copied word for word out of a book on
Servlets:

java.lang.NullPointerException
at java.io.File.<init>(File.java:180)
at java.io.FileOutputStream.<init>(FileOutputStream.java:70)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:153)
at org.apache.jasper.JspC.parseFile(JspC.java:427)
at org.apache.jasper.JspC.parseFiles(JspC.java:747)
at org.apache.jasper.JspC.main(JspC.java:762)
2002-07-07 07:35:15 - ERROR-the file
'\WEB-INF\classes\com\package\DbPoolSetup.java' generated the
following general exception: java.lang.NullPointerException


(here's the code)

import sun.misc.*;
import java.util.*;
import com.javaexchange.dbConnectionBroker.*;

public class DbPoolSetup extends HTTPservlet {
DbConnectionBroker dbPool;

protected void createDbPool() throws ServletException {
if (dbPool == null) {
try {
dbPool = new DbConnectionBroker(
getInitParameter("DriverName"),
getInitParameter("DriverType"),
+ "://"
+ getInitParameter("Host")
+ ":"
+ Integer.parseInt(getInitParameter("Port"))
+ "/"
+ getInitParmeter("DbName"),
getInitParameter("UserID"),
getInitParameter("Password"),
5,
50,
"dbconn.log",
1.0);
} catch (IOException e) { throw new ServletException(e); }
}

if (dbPool != null) {
getServletContext().setAttribute("dbPool", dbPool);
} else {
throw new ServletException("dbPoolSetup: Unable to create dbPool");
}
}

public void destroy() {
super.destroy();
try {
dbPool.destroy(10000);
} catch (SQLException e) {
System.out.println("One or more database pool connections left
open.");
}
}

public void doGet(HttpServletRequest request, HttpServletResponse
response) throws IOException, ServletException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();

out.println("<html>");
out.println("\t<head>");
out.println("\t\t<title>dbPoolSetup</title>");
out.println("\t</head>");
out.println("\t<body>");
out.println("Welcome to dbPoolSetup.");
out.println("\t</body>");
out.println("</html");

}

public void init(ServletConfig config) throws ServletException {
super.init(config);
try {
createDbPool();
} catch (ServletException e) { throw e; }
}
}


Any help here would be amazing.

Thanks,
Laz

Jon Skeet

unread,
Jul 8, 2002, 3:28:18 AM7/8/02
to
lazlo fruvous <instan...@yourmom.com> wrote:
> I am getting this message when I try to compile using "jasper jspc" on
> a servlet that i basically copied word for word out of a book on
> Servlets:
>
> java.lang.NullPointerException
> at java.io.File.<init>(File.java:180)

<snip>

Certainly the compiler shouldn't generate an NPE - that's worth
reporting to the Jasper team. However, a few points about the code
you're using which may suggest moving away from the book you copied it
from:

> (here's the code)
>
> import sun.misc.*;

You should never use sun.* packages - see
http://java.sun.com/products/jdk/faq/faq-sun-packages.html

> import java.util.*;
> import com.javaexchange.dbConnectionBroker.*;
>
> public class DbPoolSetup extends HTTPservlet

You haven't imported javax.servlet.http.* or
javax.servlet.http.HTTPServlet, so I'm not sure where it's going to get
that from... Furthermore, it should be HttpServlet rather than
HTTPServlet. If there's a class
com.javaexchange.dbConnectionBroker.HTTPServlet, that's even nastier as
it'll confuse things with javax.servlet.http.HttpServlet.

<snip>

--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

0 new messages