这是我的Register.jsp代码。我正在创建一个学生门户信息项目。当我尝试注册它接受值并将其分配给RegController servlet中的变量但它没有插入到Mysql数据库中。
<%--
Document : Register
Created on : Apr 23, 2014, 11:54:12 PM
Author : hari
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Register Page</title>
</head>
<body>
<form method="post" name="register" action="RegController">
<table>
<tr>
<td>Email</td>
<td><input type="text" name="Username" size="15" placeholder="Enter the Username" required="required"></td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" name="name" size="15" placeholder="Enter the Name" required="required"></td>
</tr>
<tr>
<td>Father Name</td>
<td><input type="text" name="fathername" size="15" placeholder="Enter the Father Name" required="required"></td>
</tr>
<tr>
<td>Age</td>
<td><input type="number" name="age" size="5" placeholder="Enter Your Age" required="required"></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="address" size="15" placeholder="Enter the Address" required="required"></td>
</tr>
<tr>
<td>Contact</td>
<td><input type="number" name="contact" size="15" placeholder="Enter the Contact" required="required"></td>
</tr>
<tr>
<td>Department</td>
<td><input type="text" name="dept" size="8" placeholder="Enter the Department" required="required"></td>
</tr>
<tr>
<td>Qualification</td>
<td><input type="text" name="qualification" size="15" placeholder="Enter the Qualification" required="required"></td>
</tr>
<tr>
<td>College</td>
<td><input type="text" name="college" size="50" placeholder="Enter the College Name" required="required"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="Password" size="15" placeholder="Enter the Password" required="required"></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Register"></td>
<td>To Login<a href="index.jsp">Click here</a></td>
</tr>
</table>
</form>
</body>
</html>
这是我的Servlet代码RegController.java
import java.sql.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.*;
import static java.lang.System.out;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author hari
*/
@WebServlet(name = "RegController", urlPatterns = {"/RegController"})
public class RegController extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
String name=request.getParameter("name");
//out.println("name"+name);
String Username=request.getParameter("Username");
String age=request.getParameter("age");
String fathername=request.getParameter("fathername");
String address=request.getParameter("address");
String phno=request.getParameter("contact");
String dept=request.getParameter("dept");
String qualification=request.getParameter("qualification");
String college=request.getParameter("college");
String Password=request.getParameter("Password");
String DB_url="jdbc:mysql://localhost:3306/MYFIRSTPROJECT";
String JDBC_Driver="com.mysql.jdbc.Driver";
String UserDB="root" ;
String PassDB="";
int i=1;
Connection conn=null;
PreparedStatement pstmt=null;
//Statement stmt=null;
try{
Class.forName("com.mysql.jdbc.Driver");
//out.println("Connection");
conn=DriverManager.getConnection(DB_url,UserDB,PassDB);
String sql="insert into users VALUES(?,?,?,?,?,?,?,?,?,?)";
//stmt=conn.createStatement();
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,Username);
//stmt.executeUpdate(sql);
pstmt.setString(2,Password);
pstmt.setString(3,name);
pstmt.setString(4,fathername);
pstmt.setString(5,address);
pstmt.setString(6,age);
pstmt.setString(7,phno);
pstmt.setString(8,dept);
pstmt.setString(9,qualification);
pstmt.setString(10,college);
pstmt.executeUpdate();
pstmt.close();
//conn.close();
}
catch(SQLException se){
se.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
finally{
try{
if(pstmt!=null)
pstmt.close();
}catch(SQLException se){}
try{
if(conn!=null)
conn.close();
}catch(SQLException se){se.printStackTrace();}
}
//if(i<=1){
// out.println("Error"+i+Username);}
//else{
System.out.println("Registered Successfully");
response.sendRedirect("Welcome.jsp");
//}
}
}
Netbeans没有显示任何错误。任何人都可以帮助plzzz ....