I am trying to create a web application, and want to open up a java servlet when an HTML form is submitted. The servlet is continually giving errors (mostly 404 errors), and I have tried every solution I have seen, but none of them work.
package com.example.kahootwebapp;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/HelloServlet")
public class HelloServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter writer = response.getWriter();
writer.println("<html><body>");
writer.println("<h1>This is a test</h1>");
writer.println("</html></body>");
}
}
<form name="HelloServlet" method="post" action="HelloServlet">
<label id="label" for="input">Enter kahoot account email: </label><input type="text" id="input" name="username"/>
</form>
I am running the server on Apache Tomcat, version 10.0.16. At current time, I am just trying to get the servlet to open and run without error, and then planning on adding code to it. Thanks.