它总是出这个错误!希望高手能教教我哈~!
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>
---------------------------------------------------------------------------------------

解决方案 »

  1.   

    rs结果集你都关闭了,当然取不了值了, 你把rs最后关就可以了
      

  2.   

    finally { 
    try { 
    if (rs != null) { 
    rs.close(); 
    rs = null; 
    } 在获取namea=rs.getString("name")之前, rs已经被close()了, namea当然就会null了, 所以系统抛出java.lang.NullPointerException错误
      

  3.   

    <%@ 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"); 
    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> 
      

  4.   

    你的数据库连接上没有,有没有获取到Connection哦
      

  5.   


    把你的这段代码
      <% 
      namea=rs.getString("name"); 
    pricea=rs.getString("price"); 
    descriptiona=rs.getString("description"); 
      %> 放到rs = stmt.executeQuery("select * from show where id=1");
    这句后边
      

  6.   

    把这句
    namea=rs.getString("name"); 
    pricea=rs.getString("price"); 
    descriptiona=rs.getString("description"); 
    移到上边的
    rs = stmt.executeQuery("select * from show where id=1"); 
    后边
      

  7.   

    最好不要都用<%%>标签,看的代码晕。
    最好分离。