Issue:
I am trying use the html form to make a get request to my java servlet but I am getting a 404 error.
I have tried changing the path from the action tag to /Main and /Assignment9Test/Main and neither are working. When I run the Java servlet it shows as http://localhost:8080/Assignment9Test/Main3.java and shows the servlet code in the browser
Endpoint I am trying to reach – http://localhost:8080/Assignment9Test/Main3?param1=1¶m2=2¶m3=3
Error – HTTP Status 404 – Not Found
File Structure
Main.html
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; ">
<title>A Sample form using GET</title>
</head>
<body bgcolor="#fdf5e6">
<center>
<h2>Collecting Three Parameters</h2>
<form action="http://localhost:8080/Assignment9Test/Main3" method="get">
First Parameter :
<input type="text" name="param1"><br>
Second Parameter: <input type="text" name="param2"><br>
Third Parameter :
<input type="text" name="param3"><br>
<input type="submit" value="Submit">
</form>
</center>
</body>
</html>
web.xml
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>Assignment9Test</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>default.htm</welcome-file>
</welcome-file-list>
</web-app>
Main.java
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("/Main3")
public class Main extends HttpServlet {
static final long serialVersionUID = 1L;
public Main() {
super();
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
//String title = "Reading Three Request Parameters";
//out.println(
//"<html>n" +
//"<head><title>" + title + "</title></head>n" +
//"<body bgcolor="#ff5e6">n" +
//"<h1 align="center">" + title + "</h1>n" +
//"<ul>n" +
//" <li><b>param1</b>: " + request.getParameter("param1") + "n" +
//" <li><b>param2</b>: " + request.getParameter("param2") + "n" +
//" <li><b>param3</b>: " + request.getParameter("param3") + "n" +
//"</ul>n" +
//"</body></html>");
}
}