我正在尝试使用 eclipse ee 和 tomcat 通过 eclipse 启动服务器从 HTML 到 Java Servlet。但我得到:HTTP 状态 405 - 此 URL 不支持 HTTP 方法 POST
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
</script>
</head>
<body>
<form method="POST" action="AddHost">
Host name : <input name="hostname" type="text"><br>
Genre : <input name="genre" type="text" ><br>
<input type="submit" value="add host">
</form>
</body>
</html>
这是小服务程序:
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
@WebServlet("/AddHost")
public class Addhost extends HttpServlet {
public void doPost(HttpServletResponse res,HttpServletRequest req) throws IOException{
String hostname = req.getParameter("hostname");
String genre = req.getParameter("genre");
}
public void doGet(HttpServletResponse res,HttpServletRequest req) throws IOException{
doPost(res,req);
}