I am making a simple Maven Project using Eclipse. There is a form that has Username and Password and a submit button.When I enter and submit the default username(admin) and password(admin). It should either show a page with "Pass" or "Fail" text if they match. But when I submit the form it shows [this error.] (https://i.stack.imgur.com/dw6Rt.png). I am using Tomcat version 10.1 with javax servlet version 4.0.1 for this project and Eclipse EE edition.
This is my file directory for the project.
I have installed the required dependency in the pom.xml file and got the servlet in the web.xml file as well. But I don't know why this issue is still there. I have tried other similar stack overflow solutions and from Google too but none of them worked so far.
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%><!DOCTYPE html><html><head><meta charset="ISO-8859-1"><title>Insert title here</title></head><body><form action="loginServlet" method="POST"><h1>JSP Page</h1><input type="text" name="username"><input type="password" name="password"><input type="submit" value="Login" id="login"></form></body></html>
Success.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%><!DOCTYPE html><html><head><meta charset="ISO-8859-1"><title>Test Page</title></head><body><% out.println("Pass"); %></body></html>
Error.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%><!DOCTYPE html><html><head><meta charset="ISO-8859-1"><title>Test Page</title></head><body><% out.println("Fail"); %></body></html>
LoginServlet.java
package com.examSolution;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;/** * Servlet implementation class LoginServlet */@WebServlet("/loginServlet")public class LoginServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); String username = request.getParameter("username"); String password = request.getParameter("password"); if(username.equals("admin") && password.equals("admin")) { response.sendRedirect("Success.jsp"); }else { response.sendRedirect("Error.jsp"); } }}