我正在尝试处理Java中基本HTML表单的输入。但是,每当我单击表单上的提交按钮时,我都会收到此错误:“在此服务器上找不到请求的URL / formHandler。”
以下是表单和Java servlet,它们都位于同一目录中,以及该站点的所有其他文件。有没有找到servlet的想法?
FORM
<form method="post" action="formHandler">
<label for="name">Name: </label>
<input name="name" defaultValue="name"/><br/>
<label for="email">Email: </label>
<input name="email" defaultValue="email"/><br/>
<label for="details">Further Details or Comments</label><br/>
<input name="details" defaultValue="details"/><br/><br/>
<input type="submit" value="Submit"/>
</form>
SERVLET
@WebServlet("/formHandler")
public class FormHandler extends HttpServlet {
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String name = request.getParameter("name");
String email = request.getParameter("email");
String details = request.getParameter("details");
PrintWriter writer = response.getWriter();
String htmlRespone = "<html>";
htmlRespone += "<h2>Thank you " + name + ", a confirmation email will be sent to " + email + " shortly.</h2>";
htmlRespone += "</html>";
writer.println(htmlRespone);
}
}