用 jsp 编写了一个对于 mysql 数据库中的数据进行删除的代码,但报错,大神指点一下啊,3Q !!!
registerform.jsp<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<html>
<head>
<title>表单</title>
</head>
<body>
<center>
<form action="registerform1.jsp" method="post">
<table align="center">
<tr>
<td colspan="2">用户删除</td>
</tr>
<tr>
<td>用户名:</td>
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td>用户ID:</td>
<td><input type="text" name="userid"/></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="删除"/> <input type="reset" value="重置"/></td>
</tr>
</table>
</form>
</center>
</body>
</html>
registerform1.jsp
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>数据库操作</title>
</head>
<body>
<%
request.setCharacterEncoding("gbk");
String userid1=request.getParameter("userid");
String username1=request.getParameter("username");
%>
<%
Connection conn=null;
PreparedStatement pre=null;
String url="jdbc:mysql://localhost:3306/javaweb";
String user="root";
String password="504979454";
try{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection(url,user,password);
}catch(ClassNotFoundException e){
out.println("加载JDBC失败");
}catch(SQLException e){
out.println("数据库加载失败");
}%>
<%try{
String adduser="delete from customers where ID=? and NAME=?";
pre=conn.prepareStatement(adduser);
pre.setString(1,userid1);
pre.setString(2,username1);
int number=pre.executeUpdate();
if(number==0){
%>
<jsp:forward page="registerform.jsp"/><%} %>
<%} %>
<%catch(SQLException e){
out.println("删除数据失败");
e.printStackTrace();
}
try{
if(pre!=null){
pre.close();
pre=null;
}
if(conn!=null){
conn.close();
conn=null;
}
}catch(SQLException e){
out.println("数据库关闭失败");
}
%>
</body>
</html>
执行结果:
HTTP Status 500 - org.apache.jasper.JasperException: Unable to load class for JSP
--------------------------------------------------------------------------------
type Exception report
message org.apache.jasper.JasperException: Unable to load class for JSP
description The server encountered an internal error that prevented it from fulfilling this request.
exception
数据库:
ID NAME AGE
1 leili 24
2 leilxxi 22
3 james 21