404
1. Servlet configuration
Pay attention to the mapping between servlet and servlet-mapping, pay attention to whether the servlet-class is written correctly, if it is correct, you can click on it with the mouse
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>servlet.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
2. Stored webpage location
login.html is located in the WebContent directory, alongside META-INF and WEB-INF
- WebContent
- META-INF
- WEB-INF
- login.html
3. Access path
Address/Project Name/Webpage
http://127.0.0.1/servlet/login.html
Address/project name/corresponding url-pattern
http://127.0.0.1/servlet/hello
405
The form method does not match the servlet processing method
If the form method is post, the servlet background processing method must also be doPost
<form action="login" method="post">
账号: <input type="text" name="name"> <br>
密码: <input type="password" name="password"> <br>
<input type="submit" value="登录">
</form>
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String name = request.getParameter("name");
String password = request.getParameter("password");
System.out.println("name:" + name);
System.out.println("password:" + password);
}