当前位置: 代码迷 >> Java Web开发 >> servlet 连接mysql数据库时出现异常,麻烦高手帮看看
  详细解决方案

servlet 连接mysql数据库时出现异常,麻烦高手帮看看

热度:4270   发布时间:2013-02-25 21:10:02.0
servlet 连接mysql数据库时出现错误,麻烦高手帮看看
servlet 连接mysql数据库时出现错误,麻烦高手帮看看
对数据库实现插入操作
浏览器显示下面信息
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet.init() for servlet insert threw exception
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
java.lang.Thread.run(Thread.java:619)
root cause

java.lang.NullPointerException
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:169)
org.sunxin.lesson.jsp.bookstore.insert.init(insert.java:31)
javax.servlet.GenericServlet.init(GenericServlet.java:212)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
java.lang.Thread.run(Thread.java:619)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.



  


addStuInfo.jsp页面
<%@ page contentType="text/html" language="java" import="java.util.*" pageEncoding="GB2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
  <script type="text/javascript"">
  function validate()
  {
  var id = document.forms[0].id.value;
  var name = document.forms[0].name.value;
  var age = document.forms[0].age.value;
  var major = document.forms[0].major.value;
  if(id <= 0){
  alert("学号不能为空,请输入学号!");
  return false;
  }
  else if(name.length <= 0){
  alert("姓名不能为空,请输入姓名!");
  return false;
  }
  else if(age <= 0){
  alert("请输入合法年龄!");
  return false;
  }

  else if(major.length <= 0){
  alert("专业不能为空,请输入所学专业!");
  return false;
  }

  else{
  return true;
  }
  //document.getElementById("form").submit();
  }
  </script>
  <head>
  <base href="<%=basePath%>">
   
  <title>Welcome,home</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>
  相关解决方案