I am creating a basic demo project for servlet but I keep getting this error whenever I run the project or index.html file. I have mentioned the servlet configurations in the web.xml. Also, I have added servlet jar files into my build path.
I cannot figure out why I am getting this error. I tried many solutions on the internet but none seems to be working.
Here are files. and the directory structure is this.
package Main;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Login extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
Login(){
super();
}
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
{
System.out.println("servlet called");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<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" version="4.0">
<display-name>FirstServlet</display-name>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>Main.Login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/Login</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
<!DOCTYPE html>
<html>
<body>
<form action="Login" method="get">
<input type="text" name="username"/><br>
<input type="text" name="password"/>
<input type="submit" value="Login"/>
</form>
</body>
</html>