For the below mention set of simple code i still get the error 404.
HTTP Status 404 – Not Found
Type Status Report
Message /DemoServlet
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/9.0.0.M26
it used to work but now it doesnt. i have tried reinstalling eclipse and it still did not help. I use a MackBook Pro. My Codes:
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="/DemoServlet" method="post">
Enter name: <input type="text" name="n"/><br>
<input type="submit" value="Validate" name="s"/>
</form>
</body>
</html>
Servlet:
package app.controller;
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("/DemoServlet")
public class DemoServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public DemoServlet() {
super();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String name=request.getParameter("n");
if(name.equals("Rajiv")) {
out.println("Welcome Rajiv");
}else
out.println("Please try again.");
}
}