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

有关问题:为什么在对数据库进行操作时,用第一个IE能操作成功,而再打开第二个IE不能进行操作,但第一个还是可以正常操作

2013-09-11 
问题:为什么在对数据库进行操作时,用第一个IE能操作成功,而再打开第二个IE不能进行操作,但第一个还是可以

问题:为什么在对数据库进行操作时,用第一个IE能操作成功,而再打开第二个IE不能进行操作,但第一个还是可以正常操作。
出现下列错误
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:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root   cause  
java.lang.NullPointerException
org.apache.jsp.in_jsp._jspService(in_jsp.java:85)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note   The   full   stack   trace   of   the   root   cause   is   available   in   the   Apache   Tomcat/5.0.30   logs.
--------------------------------------------
Apache   Tomcat/5.0.30

问题:为什么在对数据库进行操作时,用第一个IE能操作成功,而再打开第二个IE不能进行操作,但第一个还是可以正常操作。
小弟才接触JSP,各位多多指点~~,有那些应注意的地方,就直说~~

备注:jsp+mysql   5.0+tomcat   5.0;
架构:jsp+javabean+database;

文件名为:in.jsp
类名为:DBConn.class

类源文件和jsp源文件如下
package   huo;
import   java.sql.*;
import   java.lang.*;
import   java.io.*;
import   java.util.*;
public   class   DBConn{
String   dbname= "a ";
String   dburl= "jdbc:mysql://localhost/ ";
String   dbuser= "root ";
String   dbpwd= "r ";
Connection   con=null;
ResultSet   rs=null;
Statement   stm=null;
public   DBConn(){
try{
Class.forName( "com.mysql.jdbc.Driver ");
}catch(java.lang.ClassNotFoundException   e){
System.out.println( "加载驱动失败 ");
}
}//end   DBConn

public   void   ConnDB(String   dbname,String   dburl,String   dbuser,String   dbpwd){//数据库名,地址,用户名和密码
this.dburl=dburl+dbname;
this.dbuser=dbuser;
this.dbpwd=dbpwd;
try{
this.con=DriverManager.getConnection(this.dburl,this.dbuser,this.dbpwd);
//this.con=con;
this.stm=con.createStatement();
//this.stm=stm;
}catch(SQLException   e){
System.out.println( "数据库连接失败 ");
}
}//end   ConnDB
public   ResultSet   executQuery(String   sql){
try{

rs=this.stm.executeQuery(sql);
}
catch(SQLException   ex){
//System.err.println(ex.getMessage());
System.out.println( "记录集获取失败 ");
}
return   rs;
}//end   executquery
public   void   executUpdate(String   sql){
try{

stm.executeUpdate(sql);
}
catch(SQLException   ex){
//System.err.println(ex.getMessage());
System.out.println( "更新操作失败 ");
}
//return   true;
}//end   executupdate


public   void   CloseDB(){
con=null;
stm=null;
rs=null;
}
}

in.jsp:

<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   import= "java.sql.* "   errorPage= " "   %>
<%@   page   import= "java.util.* "   %>
<%@   page   import= "huo.* "   %>
<%@   page   pageEncoding= "gb2312 "%>
<%request.setCharacterEncoding( "gb2312 ");%>
<jsp:useBean   id= "test2 "   class= "huo.DBConn "/>  
<html>
<head>
<title> 数据测试页面 </title>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
</head>
<body>
<table   width= "760 "   border= "10 "   align= "center "   cellpadding= "2 "   cellspacing= "2 "   >
<tr>
<td> <div   align= "center "> id </div> </td>
<td> <div   align= "center "> title </div> </td>
</tr>
<%String   sql= "select   *   from   a ";
ResultSet   rs2=null;
ResultSet   rs=null;
String   kk=null;
String   title=null;
int   id;  
String   tempp= "test ";
  String   name= "root ";
  String   pwd= "r ";
  String   url= "jdbc:mysql://localhost/ ";
  String   dbname= "a ";
  test2.ConnDB(dbname,url,name,pwd);
kk=request.getParameter( "test ");
  if   (kk.equals(tempp))
{
        String   temp=request.getParameter( "title ");
temp=new   String(temp.getBytes( "gb2312 "), "gb2312 ");
sql= "insert   into   a   values( "+request.getParameter( "id ")+ ", ' "+temp+ " ') ";
test2.executUpdate(sql);
rs=test2.executQuery( "select   *   from   a ");
while   (rs.next())
  {
id   =rs.getInt(1);
title=rs.getString(2);
%>
<tr>
<td> <div   align= "center "> <%=id%> </div> </td>
<td> <div   align= "center "> <%=title%> </div> </td>
</tr>
<%  
}
rs.close();
test2.CloseDB();
}
%>
</table>
  <table   align= "center "   border= "2 ">
<form   method= "post "   action= "in.jsp "   >
<tr>
<td> id   :   </td>  
<td>     <input   type= "text "   name= "id "> </td>
</tr>
<tr>
<td> content:   </td>
      <td>   <textarea   name= "title "     > </textarea> </td>
      </tr>
      <tr>
      <td> d <input   name= "test "       type= "hidden "     value= "test "> </td>


      <td>
        <input   type= "submit "   name= "ok "   value= "oksub ">
</td>
</form>
</tr>
</table>
</body>
</html>

[解决办法]
空指针貌似会出在这里:
kk=request.getParameter( "test ");
if (kk.equals(tempp))
你如果在浏览器直接访问这个页面,那肯定会抛异常的。请检查你访问in.jsp的时候,是否有传参数test过来。
[解决办法]
可能就是楼上说得,你的kk是null,并不一定是操作数据库的空指针
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html

热点排行