我正在尝试提交一个简单的表单以在 servlet 中进行处理,但每次提交时我都会收到 404。代码可以正常编译和部署。我已经完成了关于这个主题的几乎所有教程,所以我知道那里有很多关于它的信息。关于我犯了哪个菜鸟错误有什么建议吗?提前感谢您的帮助!
jsp 位于 /webapps/registerWidget servlet 位于 /webapps/registerWidget/WEB-INF/classes/com/sample/applet web.xml 位于 /webapps/registerWidget/WEB-INF
这是我的jsp:
<!DOCTYPE HTML>
<html>
<head>
<title>Sample Applet</title>
</head>
<body>
<header>Please Register</header>
<section>
<form action="/register" method="POST">
First name: <input type="text" name="firstname"><br>
Last name: <input type="text" name="lastname"><br>
Email: <input type="text" name="email"><br>
<input type="submit" value="Submit">
</form>
</section>
</body>
</html>
这是我的小服务程序:
package com.sample.applet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class RegisterServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
doPost(req, res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException {
String first = req.getParameter("firstname");
String last = req.getParameter("lastname");
String email = req.getParameter("email");
....some processing code....
}
}
这是我的 web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/Web-app_2_4.xsd">
<servlet>
<servlet-name>registerServlet</servlet-name>
<servlet-class>com.sample.applet.RegisterServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>registerServlet</servlet-name>
<url-pattern>/register</url-pattern>
</servlet-mapping>
</web-app>