我是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 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NullPointerException org.apache.jsp.jsp.default_jsp._jspService(org.apache.jsp.jsp.default_jsp:102) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.12 logs.
default.jsp页面的源代码:
<%@page contentType="text/html;charset=GBK" %>
<%@page import="load.*,java.sql.*" %>
<jsp:useBean id="conn" scope="page" class="load.conn"/>
<jsp:useBean id="rstogbk" scope="page" class="load.RsToGbk"/>
<%! ResultSet rs=null; %>
<html>
<head>
<title>我的软件仓库</title>
<Link rel="stylesheet"type="text/css" href="style.css">
</head>
<body TEXT="#000000"BGCOLOR="#FFFFFF"BACKGROUND="b01.jpg">
<Center>
<%@include file="title.htm" %>
<h2>我的软件仓库-软件排行榜</h2>
</Center>
<%
String sql="Select Top 10 *From download Order By hits DESC";
rs=conn.executeQuery(sql);
while(rs.next()){
out.println(rstogbk.RsToGbook(rs));
}
%>
</body>
</html>
我连接数据库的JavaBean的代码:
package load;
import java.sql.*;
public class conn{
String sDBDriver="sun.jdbc.odbc.jdbcOdbcDriver";
String sConnStr="jdbc:odbc:download";
Connection connect=null;
ResultSet rs=null;
public conn(){
try{
Class.forName(sDBDriver);
} catch(java.lang.ClassNotFoundException e){
System.err.println(e.getMessage());
}
}
public ResultSet executeQuery(String sql){
try{
connect=DriverManager.getConnection(sConnStr);
Statement stmt=connect.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery(sql);
}
catch(SQLException ex){
System.err.println(ex.getMessage());
}
return rs;
}
public int executeUpdate(String sql){
int result=0;
try{
connect=DriverManager.getConnection(sConnStr);
Statement stmt=connect.createStatement();
result=stmt.executeUpdate(sql);
}
catch(SQLException ex){
System.err.println(ex.getMessage());
}
return result;
}
}