我用eclipse+myeclipse+tomcat建了3个文件,在Oracle中建了一个表,然后运行文件,但是连接Oracle时出现异常,好像是找不到Oracle的驱动

时间:2023-01-22 16:41:00
RT。
异常如下:

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
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


root cause 

java.lang.NullPointerException
org.apache.jsp.index_jsp._jspService(index_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


note The full stack trace of the root cause is available in the Tomcat logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.12


我已将ojdbc14.jar放到了C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\myjsp\WEB-INF\lib下;

C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib下,
可还是出现同样的异常,
是不是要配置环境变量,还是要在eclipse里添加、配置什么呢?

  感激不尽!!

4 个解决方案

#1


root cause 
java.lang.NullPointerException

空指针错误,看起来不像是配置问题,应该是你的jsp有问题,再仔细检查一下有没有类没有create就引用之类的错误。

#2


哦,我看一下。。。

#3


大家能不能帮帮忙跟我一起找呀,谢谢啦!!
下面是3个文件的代码,大家看看是哪里有错:
index.html:
<html>
<head>
<title>留言板</title>
</head>
<body bgcolor="#ccc231" vlink="#000000" alink="#666666">
<DIV align="center">
<p><FONT size="7">
<b><font size="+6"></font></b>
</FONT>
</p>
<FORM method="post" action="index.jsp">
<TABLE width="75%" align="center" border=1>
<TR>
<TD width="30%">
<div align="right">姓名:</div>
</TD>
<TD width="70%">
<INPUT type="text" name="name">
</TD>
</TR>
<TR>
<TD width="30%">
<DIV align="right">电子邮件:</DIV>
</TD>
<TD width="70%">
<INPUT type="text" name="email">
</TD>
</TR>
<TR>
<TD width="30%">
<div align="right" >个人主页地址:</div>
</TD>
<TD width="70%">
<TEXTAREA name="body" rows="5" cols="30"></TEXTAREA>
</TD>
</TR>
<TR>
<TD width="30%">&nbsp;</TD>
<TD width="70%">&nbsp;</TD>
</TR>
<TR>
<TD width="30%">&nbsp;</TD>
<TD width="70%">
<TABLE width="75%">
<TR>
<TD>
<INPUT type="submit" name="send" value="提交">
</TD>
<TD>
<INPUT type="reset" name="reset" value="重置">
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</FORM>
<hr>
</DIV>
</body>
</html>



index.jsp:
<html>
<head>
</head>
<body>
<%@ page language="java" import="java.sql.*;"%> 
<%@ page contentType="text/html;charset=gb2312"%>
<jsp:useBean id="sqlbean" class="hh.Sql_data" scope="session" />
<%! String name,email,url,body,sql;%>
<%
name=request.getParameter("name");
email=request.getParameter("email");
url=request.getParameter("url");
body=request.getParameter("body");
if(name!=""&&email!=""&&body!="")
{
  sql="insert into guestbook (name,email,url,body) values ('"+name+"','"+email+"','"+url+"','"+body+"')";
  sqlbean.executeInsert(sql);
}
else
{
  out.print("<b><font color=red>Sorry,Please enter your name,email,and body!!!</font></b>");
  }
%>
<%
ResultSet RScount=sqlbean.executeQuery("SELECT * FROM guestbook");
int i=0;
while(RScount.next())
{
 i++;
 }
 %>
 <%--<p><a name=see><b>Now,<%=RScount %>Records.</b></a></p> --%>
 <p><b>现在有<%=i%>条记录</b></p>
 <%
 RScount.close();
 i=0;
 %>
 <p>&nbsp;</p>
 <%
 ResultSet RS=sqlbean.executeQuery("select * from guestbook");
 while(RS.next())
 {
  name=RS.getString("name");
  email=RS.getString("email");
  url=RS.getString("url");
  body=RS.getString("body");
  %>
  <table border=1 width=80%>
  <tr>
  <TD width=30%>昵称:</TD><TD width=70%><%=name%></TD>
  </tr>
  <TR>
  <TD width=30%>电子邮件:</TD><TD width=70%><a href="maito:<%=email%>"><%=email%></a></TD>
  </TR>
  <TR>
  <TD width=30%>个人主页地址:</TD><TD width=70%><a href="<%=url%>"><%=url%></a></TD>
  </TR>
  <TR>
  <TD width=30%>内容:</TD><TD width=70%><%=body%></TD>
  </TR>
  </table>
  <hr>
  <%
  }
  RS.close();
  %>
  </body>
  </html>
  

package hh;
import java.sql.*;
public class Sql_data {

String sDBDriver="oracle.jdbc.driver.OracleDriver";
String sConnStr="jdbc:oracle:thin:@aa-52:1521:Grace";
Connection conn=null;
ResultSet rs=null;
public Sql_data()
{
try
{
Class.forName(sDBDriver);
}
catch(ClassNotFoundException e)
{
System.err.println("sql_data():"+e.getMessage());
}
}
public void executeInsert(String sql)
{

try
{
conn=DriverManager.getConnection(sConnStr,"syetem","ffffff");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex)
{
System.out.println("sql_data.executeUpdate:"+ex.getMessage());
}
}
public ResultSet executeQuery(String sql)
{
rs=null;
try
{
conn=DriverManager.getConnection(sConnStr);
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.err.println("sql_data.executeQuery:"+ex.getMessage());
}
return rs;
}
public void executeDelete(String sql)
{
try
{
conn=DriverManager.getConnection(sConnStr);
Statement stmt=conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex)
{
System.err.println("sql_data.executeDelete:"+ex.getMessage());
}
}

}

表:guestbook:
SQL> desc guestbook
 名称                                      是否为空? 类型
 ----------------------------------------- -------- --------------------
 NAME                                      NOT NULL VARCHAR2(20)
 EMAIL                                     NOT NULL VARCHAR2(30)
 URL                                                VARCHAR2(50)
 BODY                                               VARCHAR2(200)


大家帮下忙啊,感激不尽!!!

#4


找到了一个错误后,再次运行文件,现在又出现了另外的异常了:

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: Unable to compile class for JSP
        org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:561)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


root cause 

java.lang.NullPointerException
        org.apache.catalina.loader.WebappClassLoader.findResourceInternal(WebappClassLoader.java:1792)
        org.apache.catalina.loader.WebappClassLoader.findResource(WebappClassLoader.java:944)
        org.apache.catalina.loader.WebappClassLoader.getResourceAsStream(WebappClassLoader.java:1161)
        javax.xml.parsers.SecuritySupport12$4.run(SecuritySupport12.java:119)
        java.security.AccessController.doPrivileged(Native Method)
        javax.xml.parsers.SecuritySupport12.getResourceAsStream(SecuritySupport12.java:112)
        javax.xml.parsers.FactoryFinder.findJarServiceProvider(FactoryFinder.java:263)
        javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:169)
        javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:139)
        org.apache.jasper.xmlparser.ParserUtils.parseXMLDocument(ParserUtils.java:129)
        org.apache.jasper.compiler.JspConfig.processWebDotXml(JspConfig.java:112)
        org.apache.jasper.compiler.JspConfig.init(JspConfig.java:213)
        org.apache.jasper.compiler.JspConfig.findJspProperty(JspConfig.java:229)
        org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:207)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:437)
        org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:555)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


note The full stack trace of the root cause is available in the Tomcat logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.12


这是什么问题呢?

#1


root cause 
java.lang.NullPointerException

空指针错误,看起来不像是配置问题,应该是你的jsp有问题,再仔细检查一下有没有类没有create就引用之类的错误。

#2


哦,我看一下。。。

#3


大家能不能帮帮忙跟我一起找呀,谢谢啦!!
下面是3个文件的代码,大家看看是哪里有错:
index.html:
<html>
<head>
<title>留言板</title>
</head>
<body bgcolor="#ccc231" vlink="#000000" alink="#666666">
<DIV align="center">
<p><FONT size="7">
<b><font size="+6"></font></b>
</FONT>
</p>
<FORM method="post" action="index.jsp">
<TABLE width="75%" align="center" border=1>
<TR>
<TD width="30%">
<div align="right">姓名:</div>
</TD>
<TD width="70%">
<INPUT type="text" name="name">
</TD>
</TR>
<TR>
<TD width="30%">
<DIV align="right">电子邮件:</DIV>
</TD>
<TD width="70%">
<INPUT type="text" name="email">
</TD>
</TR>
<TR>
<TD width="30%">
<div align="right" >个人主页地址:</div>
</TD>
<TD width="70%">
<TEXTAREA name="body" rows="5" cols="30"></TEXTAREA>
</TD>
</TR>
<TR>
<TD width="30%">&nbsp;</TD>
<TD width="70%">&nbsp;</TD>
</TR>
<TR>
<TD width="30%">&nbsp;</TD>
<TD width="70%">
<TABLE width="75%">
<TR>
<TD>
<INPUT type="submit" name="send" value="提交">
</TD>
<TD>
<INPUT type="reset" name="reset" value="重置">
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</FORM>
<hr>
</DIV>
</body>
</html>



index.jsp:
<html>
<head>
</head>
<body>
<%@ page language="java" import="java.sql.*;"%> 
<%@ page contentType="text/html;charset=gb2312"%>
<jsp:useBean id="sqlbean" class="hh.Sql_data" scope="session" />
<%! String name,email,url,body,sql;%>
<%
name=request.getParameter("name");
email=request.getParameter("email");
url=request.getParameter("url");
body=request.getParameter("body");
if(name!=""&&email!=""&&body!="")
{
  sql="insert into guestbook (name,email,url,body) values ('"+name+"','"+email+"','"+url+"','"+body+"')";
  sqlbean.executeInsert(sql);
}
else
{
  out.print("<b><font color=red>Sorry,Please enter your name,email,and body!!!</font></b>");
  }
%>
<%
ResultSet RScount=sqlbean.executeQuery("SELECT * FROM guestbook");
int i=0;
while(RScount.next())
{
 i++;
 }
 %>
 <%--<p><a name=see><b>Now,<%=RScount %>Records.</b></a></p> --%>
 <p><b>现在有<%=i%>条记录</b></p>
 <%
 RScount.close();
 i=0;
 %>
 <p>&nbsp;</p>
 <%
 ResultSet RS=sqlbean.executeQuery("select * from guestbook");
 while(RS.next())
 {
  name=RS.getString("name");
  email=RS.getString("email");
  url=RS.getString("url");
  body=RS.getString("body");
  %>
  <table border=1 width=80%>
  <tr>
  <TD width=30%>昵称:</TD><TD width=70%><%=name%></TD>
  </tr>
  <TR>
  <TD width=30%>电子邮件:</TD><TD width=70%><a href="maito:<%=email%>"><%=email%></a></TD>
  </TR>
  <TR>
  <TD width=30%>个人主页地址:</TD><TD width=70%><a href="<%=url%>"><%=url%></a></TD>
  </TR>
  <TR>
  <TD width=30%>内容:</TD><TD width=70%><%=body%></TD>
  </TR>
  </table>
  <hr>
  <%
  }
  RS.close();
  %>
  </body>
  </html>
  

package hh;
import java.sql.*;
public class Sql_data {

String sDBDriver="oracle.jdbc.driver.OracleDriver";
String sConnStr="jdbc:oracle:thin:@aa-52:1521:Grace";
Connection conn=null;
ResultSet rs=null;
public Sql_data()
{
try
{
Class.forName(sDBDriver);
}
catch(ClassNotFoundException e)
{
System.err.println("sql_data():"+e.getMessage());
}
}
public void executeInsert(String sql)
{

try
{
conn=DriverManager.getConnection(sConnStr,"syetem","ffffff");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex)
{
System.out.println("sql_data.executeUpdate:"+ex.getMessage());
}
}
public ResultSet executeQuery(String sql)
{
rs=null;
try
{
conn=DriverManager.getConnection(sConnStr);
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.err.println("sql_data.executeQuery:"+ex.getMessage());
}
return rs;
}
public void executeDelete(String sql)
{
try
{
conn=DriverManager.getConnection(sConnStr);
Statement stmt=conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex)
{
System.err.println("sql_data.executeDelete:"+ex.getMessage());
}
}

}

表:guestbook:
SQL> desc guestbook
 名称                                      是否为空? 类型
 ----------------------------------------- -------- --------------------
 NAME                                      NOT NULL VARCHAR2(20)
 EMAIL                                     NOT NULL VARCHAR2(30)
 URL                                                VARCHAR2(50)
 BODY                                               VARCHAR2(200)


大家帮下忙啊,感激不尽!!!

#4


找到了一个错误后,再次运行文件,现在又出现了另外的异常了:

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: Unable to compile class for JSP
        org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:561)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


root cause 

java.lang.NullPointerException
        org.apache.catalina.loader.WebappClassLoader.findResourceInternal(WebappClassLoader.java:1792)
        org.apache.catalina.loader.WebappClassLoader.findResource(WebappClassLoader.java:944)
        org.apache.catalina.loader.WebappClassLoader.getResourceAsStream(WebappClassLoader.java:1161)
        javax.xml.parsers.SecuritySupport12$4.run(SecuritySupport12.java:119)
        java.security.AccessController.doPrivileged(Native Method)
        javax.xml.parsers.SecuritySupport12.getResourceAsStream(SecuritySupport12.java:112)
        javax.xml.parsers.FactoryFinder.findJarServiceProvider(FactoryFinder.java:263)
        javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:169)
        javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:139)
        org.apache.jasper.xmlparser.ParserUtils.parseXMLDocument(ParserUtils.java:129)
        org.apache.jasper.compiler.JspConfig.processWebDotXml(JspConfig.java:112)
        org.apache.jasper.compiler.JspConfig.init(JspConfig.java:213)
        org.apache.jasper.compiler.JspConfig.findJspProperty(JspConfig.java:229)
        org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:207)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:437)
        org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:555)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


note The full stack trace of the root cause is available in the Tomcat logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.12


这是什么问题呢?