它总是出这个错误!希望高手能教教我哈~!
description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Exception in JSP: /Show.jsp:7067:
68: </head>
69: <%
70: namea=rs.getString("name");
71: pricea=rs.getString("price");
72: descriptiona=rs.getString("description");
73: %>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause java.lang.NullPointerException
org.apache.jsp.Show_jsp._jspService(Show_jsp.java:121)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)---------------------下面是代码---------------------------------------------------------------------------
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%@ page import="java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%!
String namea;
String pricea;
String descriptiona;
%>
<%
Connection coon = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver"); coon = DriverManager
.getConnection("jdbc:mysql://localhost/bbs?user=root&password=lilinqing");
stmt = coon.createStatement();
rs = stmt.executeQuery("select * from show where id=1");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
System.out.println("SQLException:" + e.getMessage());
System.out.println("SQLState:" + e.getSQLState());
System.out.println("VendorError:" + e.getErrorCode());
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (stmt != null) {
stmt.close();
stmt = null;
}
if (coon != null) {
coon.close();
coon = null;
} } catch (SQLException e) {
e.printStackTrace();
}
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'Show.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<%
namea=rs.getString("name");
pricea=rs.getString("price");
descriptiona=rs.getString("description");
%>
<body>
<p>项目编号:</p>
<p>项目名称:<%=namea %></p>
<p>项目资金:<%=pricea %></p>
<p>描述:<%=descriptiona %></p>
</body>
</html>
---------------------------------------------------------------------------------------
description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Exception in JSP: /Show.jsp:7067:
68: </head>
69: <%
70: namea=rs.getString("name");
71: pricea=rs.getString("price");
72: descriptiona=rs.getString("description");
73: %>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause java.lang.NullPointerException
org.apache.jsp.Show_jsp._jspService(Show_jsp.java:121)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)---------------------下面是代码---------------------------------------------------------------------------
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%@ page import="java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%!
String namea;
String pricea;
String descriptiona;
%>
<%
Connection coon = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver"); coon = DriverManager
.getConnection("jdbc:mysql://localhost/bbs?user=root&password=lilinqing");
stmt = coon.createStatement();
rs = stmt.executeQuery("select * from show where id=1");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
System.out.println("SQLException:" + e.getMessage());
System.out.println("SQLState:" + e.getSQLState());
System.out.println("VendorError:" + e.getErrorCode());
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (stmt != null) {
stmt.close();
stmt = null;
}
if (coon != null) {
coon.close();
coon = null;
} } catch (SQLException e) {
e.printStackTrace();
}
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'Show.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<%
namea=rs.getString("name");
pricea=rs.getString("price");
descriptiona=rs.getString("description");
%>
<body>
<p>项目编号:</p>
<p>项目名称:<%=namea %></p>
<p>项目资金:<%=pricea %></p>
<p>描述:<%=descriptiona %></p>
</body>
</html>
---------------------------------------------------------------------------------------
解决方案 »
- hibernate 级联删除删不掉!求各位大虾看看啊!
- hibernate
- Eclipse clean几次就出现java.lang.OutOfMemoryError: PermGen space
- 如何将DB文件导入MYsql
- JSP中javaScript 调用delphi插件
- struts总是报找不到action异常
- 异常!!!它是怎么引起的呢?
- 急求:《JSP应用开发详解(第二版)》随书附赠的光盘,请走过路过的帮个忙啦!!!
- JSP的显示出了个奇怪的问题,大家近来指教一下啦
- 数据类型转化问题(oracle+tomcat)
- 【跪求】jsp无法部署到Tomcat相关项目下呀!
- 怎么用JavaScript发送请求,然后再在父窗体显示查询后的结果 ???
try {
if (rs != null) {
rs.close();
rs = null;
} 在获取namea=rs.getString("name")之前, rs已经被close()了, namea当然就会null了, 所以系统抛出java.lang.NullPointerException错误
<%@ page import="java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%!
String namea;
String pricea;
String descriptiona;
%>
<%
Connection coon = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver"); coon = DriverManager
.getConnection("jdbc:mysql://localhost/bbs?user=root&password=lilinqing");
stmt = coon.createStatement();
rs = stmt.executeQuery("select * from show where id=1");
rs.next();
namea=rs.getString("name");
pricea=rs.getString("price");
descriptiona=rs.getString("description");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
System.out.println("SQLException:" + e.getMessage());
System.out.println("SQLState:" + e.getSQLState());
System.out.println("VendorError:" + e.getErrorCode());
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (stmt != null) {
stmt.close();
stmt = null;
}
if (coon != null) {
coon.close();
coon = null;
} } catch (SQLException e) {
e.printStackTrace();
}
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href=" <%=basePath%>">
<title>My JSP 'Show.jsp' starting page </title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body> <p>项目编号: </p>
<p>项目名称: <%=namea %> </p>
<p>项目资金: <%=pricea %> </p>
<p>描述: <%=descriptiona %> </p>
</body>
</html>
把你的这段代码
<%
namea=rs.getString("name");
pricea=rs.getString("price");
descriptiona=rs.getString("description");
%> 放到rs = stmt.executeQuery("select * from show where id=1");
这句后边
namea=rs.getString("name");
pricea=rs.getString("price");
descriptiona=rs.getString("description");
移到上边的
rs = stmt.executeQuery("select * from show where id=1");
后边
最好分离。