首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

org.apache.jasper.JasperException: java.lang.NullPointerException异常,求助

2013-09-11 
org.apache.jasper.JasperException: java.lang.NullPointerException错误,求助我是用jsp连接sqlserver200

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.handleJspException(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());
  }
  try /*建立连接*/
  {
  Con = DriverManager.getConnection(sConnStr,"sa",""); 
  }
  catch(SQLException e)
  {
  out.print(e.toString());
  }

  Stmt = Con.createStatement(); /*创建JDBC声明*/ 
  String query="CREATE TABLE GUEST" + /*在数据库中创建新的表*/
  "(NUM VARCHAR(32),"+ 
  "USERNAME TEXT,"+ 
  "CONTENT TEXT,"+ 
  "PASSWORD INTEGER,"+ 
  "TOTAL INTEGER,"+


  "REALNAME TEXT)"; 
  Stmt.executeUpdate(query); /*更新数据库*/

catch (Exception e) {} 
out.println("恭喜,在pubs数据库中创建guest表成功!<br>"); 
%> 

<% /*在数据库中添加数据*/
  String sql="INSERT INTO GUEST VALUES ('111','111','111','111',111,'111')"; 
  Stmt.executeUpdate(sql);
  out.println("向guest表添加数据成功!");
%>

<%
ResultSet RS= Stmt.executeQuery("SELECT * FROM Guest"); /*连接到数据库中的表GUEST上*/
String tt; /**号表示选择表中所有的列*/
String link; /*若选择其中的某几列可以将*号换成列标号*/  
String makeStr; /*WHERE语句表示条件选择*/
out.print("<table border=2 style=color:blue >");
while (RS.next()) {
  out.print("<tr><td>");
  tt = RS.getString("NUM"); /*查询表中NUM字段的内容*/
  out.print(tt);
  out.print("</td><td>");
  tt = RS.getString("USERNAME");
  out.print(tt);
  out.print("</td><td>");
  tt = RS.getString("CONTENT");
  out.print(tt);
  out.print("</td><td>");
  tt=RS.getString("PASSWORD");
  out.print(tt);
  out.print("</td><td>");
 } 
out.print("</table>");
RS.close();
out.println("从数据库表guest数据查询成功!");
%>
</body>
</html>



[解决办法]
一但出现异常,对象就不会被赋值了,建议在出现异常的时候,直接return.
自己把代码都剪切出来,然后一点点粘回去,看看哪句错了。
[解决办法]
简易楼主把加表,查询,删除分开运行!看看到底是那一部分出的错呀!
[解决办法]
你去到tomcat的目录下的work的文件夹,去找到dbprogram_jsp.java这个文件,它就是JSP编译后的Java文件,看里边的116行就可以了.
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html

热点排行