I am getting this error on using post method in my form-- HTTP Status 405 - HTTP method POST is not supported by this URL.
我register.html文件如下:
Register formName:
Email ID:
Password:
我Register.java servlet代码是如下
package Glassfish;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
/**
*
* @author Intel I 5
*/
public class Register extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String name = request.getParameter("name");
String email = request.getParameter("email");
String pass = request.getParameter("pass");
try{
//loading drivers for mysql
Class.forName("com.mysql.jdbc.Driver");
//creating connection with the database
Connection con=DriverManager.getConnection
("jdbc:mysql://localhost:3306/test","user","pass");
PreparedStatement ps=con.prepareStatement
("insert into register values(?,?,?)");
ps.setString(1, name);
ps.setString(2, email);
ps.setString(3, pass);
int i=ps.executeUpdate();
if(i>0)
{
out.println("You are sucessfully registered");
}
}
catch(Exception se)
{
se.printStackTrace();
}
}
我的web.xml文件如下
Register
Glassfish.Register
Register
/Register
30
我已经尝试了HTTP错误405中提供的所有实例,用于堆栈溢出中的post方法但没有用。