0

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.");
    }

}
  • is your application deployed to the root context? typically they are deployed to a context such as /myapp for myapp.war - which would put DemoServlet at /myapp/DemoServlet – slipperyseal Sep 28 '17 at 03:13
  • please check this post https://stackoverflow.com/questions/14018215/what-is-url-pattern-in-web-xml-and-how-to-configure-servlet/14018272#14018272 – Ravi Sep 28 '17 at 03:40

0 Answers0