<%@page language="java" contentType="text/html" import="java.sql.*" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Register</title>
</head>
<body>
<form>
<table width="300">
<tr>
<td>Enter User Name:<td><input type="text" name="uname">
</tr>
<tr>
<td>Enter Password:
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td><button name="b1" >Save</button>
<td><input type="reset" name="rs" value="Reset"></td>
</table>
</form>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/projectjsp", "root", "");
Statement s = con.createStatement();
String a = request.getParameter("uname");
String b = request.getParameter("pass");
String q = "insert into userlogin (username,password) values ('" + a + "','" + b + "')";
s.execute(q);
out.print(q);
%>
</body>
</html>
在Web浏览器中打开它时会显示错误和异常
javax.servlet.ServletException:com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:键'PRIMARY'的重复条目'null'
当代码被删除时,页面显示正常。