org.apache.jasper.JasperException:
java.lang.NullPointerException错误,求助
我是用jsp连接sqlserver2000数据库的,书上有这样一个文件,dbprogram.jsp(代码如下),是用来连接查询并显示记录的,我把他放在D:\Tomcat 6.0\webapps\ROOT这个目录下面,在浏览器中输入http://localhost:8080/dbprogram.jsp,弹出来了错误:
HTTP Status 500 -
--------------------------------------------
type Exception report
message
description
The server encountered an internal error () that prevented it from fulfilling this request.exception
org.apache.jasper.
JasperException: java.lang.
NullPointerException org.apache.jasper.servlet.JspServletWrapper.handle
JspException(JspServletWrapper.java:541)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.NullPointerException
org.apache.jsp.dbprogram_jsp._jspService(dbprogram_jsp.java:116)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.
在这前我已经把sql2000的驱动程序安装好了,并把里面的三个包放在了D:\Tomcat 6.0\lib这个目录下面,还在classpath中设为.;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;c:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar
我觉得应该没有错了,下面是那个jsp文件:
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page info="database handler"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<!--导入结束-->
<html>
<head>
<title>数据库连接实验</title>
</head>
<body>
<%
String sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String sConnStr = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";//
Connection Con = null;
Statement Stmt = null;
try
{
try /*加载驱动程序*/
{
Class.forName(sDBDriver).newInstance();
}
catch(
java.lang.ClassNotFoundException e)
{
out.print("Connect to Database error: " + e.getMessage());
}