相同的代码适用于其他PC,我的连接相同并导入了所有必需的文件
我在YouTube上尝试了所有解决方案,但没有解决我的错误
在 Register.html
中<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Registration Form</title>
</head>
<body>
<cl>
<h1 align="center">Registration Form</h1>
<form action="servlet/ServletRegister" method="post">
<table align="center">
<tr>
<td>First Name:</td>
<td><input type="text" name="FirstName" required></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="LastName" required></td>
</tr>
<tr>
<td>DOB:</td>
<td><input type="date" name ="DateOfBirth" required></td>
</tr>
<tr>
<td>Mobile.No:</td>
<td><input type="tel" name="MobileNo" required></td>
</tr>
<tr>
<td>E-Mail:</td>
<td><input type="email" name="Email" required></td>
</tr>
<tr>
<td>Create Password:</td>
<td><input type="password" name="Password" required></td>
</tr>
<tr>
<td>Address:</td>
<td><textarea name="Address"></textarea><br></td>
</tr>
</cl>
<tr>
<td></td>
<td><input type="submit" value= "Save Data">  
<input type="reset" value="clear"></td>
</tr>
</table>
<br><br>
<div align="center">           Already Registered..?   <a href="LoginPage.html">Click Here.</div>
</form>
</body>
</html>
在 ServletRegister.java
中import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/ServletRegister")
public class ServletRegister extends HttpServlet {
private static final long serialVersionUID = 1L;
public ServletRegister() {
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out= response.getWriter();
String fn= request.getParameter("FirstName");
String ln= request.getParameter("LastName");
String dob= request.getParameter("DateOfBirth");
String mbno= request.getParameter("MobileNo");
String mail= request.getParameter("Email");
String pwd= request.getParameter("Password");
String addr= request.getParameter("Address");
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/vikas","root","rass");
PreparedStatement ps=con.prepareStatement("insert into reg values(?,?,?,?,?,?,?)");
ps.setString(1, fn);
ps.setString(2, ln);
ps.setString(3, dob);
ps.setString(4, mbno);
ps.setString(5, mail);
ps.setString(6, pwd);
ps.setString(7, addr);
int i= ps.executeUpdate();
if(i>0)
{
//response.sendRedirect("Images/images.jpg");
out.println("Registered Successfully");
}
else
{
out.println("Not Registered");
}
}
catch(Exception e)
{
System.out.println(e);
}
out.close();
}
}
答案 0 :(得分:0)
您的表单操作已映射到servlet/ServletRegister
<form action="servlet/ServletRegister" method="post">
但是你的servlet有不同的映射:
@WebServlet("/ServletRegister")
您需要更改表单映射以匹配servlet映射:
<form action="ServletRegister" method="post">