I am running the following code, Which is html version, It shows the name and age boxes.
<!-- Main.html -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>A First page</title>
</head>
<body>
<form action="Thanks.jsp" method="get">
Enter Your Name: <input type="text" name="yourName"><br>
Enter Your Age :<input type="text" name="yourAge"><br>
<input type="submit" value="Sumitting">
</form>
</body>
</html>
but when i run the code of same logic which is a servlet version, it got an error
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Code as follows :
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
@WebServlet("/Main")
public class Main extends HttpServlet {
private static final long serialVersionUID = 1L;
public Main() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
PrintWriter out = response.getWriter(); //Is added
out.println("<form action=\"http://localhost\" method=\"post\">");
out.println("Enter Your Name: <input type=\"text\" name " +
"= \"yourName=\" </input><br>");
out.println("Enter Your Age : <input " +
"type=\"text\" name = \"yourAge=\" </input>");
out.close();
}
}
Adding web.xml as requested by @RomanC
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="w3.org/2001/XMLSchema-instance"
xmlns="xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="xmlns.jcp.org/xml/ns/javaee
xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<servlet>
<servlet-name>abc</servlet-name>
<servlet-class>yi.Main</servlet-class>
</servlet>
</web-app>