我有一个signup.jag (粗略的页面)供用户注册。我有一个用于 javascript 验证的signup.js (javascript) 。
我想通过 java 即 jdbc 将用户信息存储在 mysql 数据库中,为此我编写了以下文件名sigunp.java的代码:
import java.io.*;
import java.lang.*;
import java.sql.*;
import java.servlet.*;
import java.servlet.http.*;
public class signupdb extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException IOException
{
response.setContentType(text/html);
PrintWriter pw = response.getWriter();
String connectionURL = "jdbc:mysql://localhost:3306/ticketing";
Connection connection;
try
{
String firstname = request.getParameter("fname");
String lastname = request.getParameter("lname");
String phonenum = request.getParameter("phone");
String addr = request.getParameter("address");
String email = request.getParameter("email");
String password = request.getParameter("pass");
pw.println(firstname);
pw.println(lastname);
pw.println(phonenum);
pw.println(addr);
pw.println(email);
pw.println(password);
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(connectionurl,"root","suselinux");
PreparedStatement pst = connection.prepareStatement("insert into userinfo values(?,?,?,?,?,?)");
pst.setString(1,firstname);
pst.setString(2,lastname);
pst.setString(3,phonenum);
pst.setString(4,addr);
pst.setString(5,email);
pst.setString(6,password);
int i = pst.executeUpdate();
if(i != 0)
{
pw.println("<br>Record has been inserted");
}
else
{
pw.println("No Data Inserted");
}
}
catch(Exception e)
{
pw.println(e);
}
}
}
但是当我启动jaggery 服务器并提交数据时,它显示错误 404。