[![enter image description here][1]][1]Hi everyone I am making a web application in Java using servlets. For this I am using eclipse neon.3 , Apache tomcat 9.0.0 , mysql and java jdk 8 I have made a dynamic web application in eclipse and I used database connection
//Servlet login.java
package login;
import java.sql.*;
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.sql.SQLException;
import javax.servlet.http.HttpSession;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import login.logindb;
@WebServlet("/login")
public class login extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username= request.getParameter("username");
String password=request.getParameter("password");
boolean ISFiled = false;
try
{
ISFiled = logindb.check(username, password); // need to add message here for successful/unsuccesful operation
}
catch (SQLException e)
{
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(ISFiled == true)
{
response.sendRedirect("success.jsp");
}
else {
response.sendRedirect("welcom.jsp");}
}
}
Signup.jsp
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title>Sign Up</title>
<style>
.col-md-6{
width: 1200;
justify-content: left;
align-items: left;
}
</style>
</head>
<body>
<div class="container col-md-9 col-md-offset-5" style="overflow: auto">
<form action="SignupServlet1" method="post">
<section class="section mt-5">
<div class="container">
<div class="row">
<div class="col-md-5">
<div>
<img alt="Web Studio" class="img-fluid" src="https://media.istockphoto.com/id/1354441996/photo/image-of-open-antique-book-on-wooden-table-with-glitter-overlay.jpg?b=1&s=170667a&w=0&k=20&c=O_VZbgONe4WTXPOEvwKYezhqFkzAXpr2g-lCdpdj5FU="
/>
</div>
</div>
<div class="col-md-6 col-lg-5 ml-auto d-flex align-items-center mt-15 mt-md-4">
<div>
<h1>Sign Up </h1>
<div class="form-group">
<button type="submit" class="btn btn-primary">SignUp</button>
</div> </div>
</div>
</div>
</section>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</form>
</div>
</body>
</html
SignupServlet
package login;
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.sql.SQLException;
import javax.servlet.http.HttpSession;
import login.UserRegister;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
@WebServlet(name="abc",urlPatterns={"/SignupServlet"})
public class SignupServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
register( request, response);
}
private void register(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.sendRedirect("login.jsp");}
}
}
now when i add the jsp pages it works the login servlet is also working but when i added the sigup servlet it shows 404 error. I searched a lot but I can't get what's wrong here I checked for annotations I couldn't find anything wrong then I checked for web.xml file it showed a table like format so I opened it with DTD editor so I was able to write into the file
<?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_3_1.xsd" version="3.1">
<servlet>
<servlet-name>abc</servlet-name>
<servlet-class>login.SignupServlet1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>abc</servlet-name>
<url-pattern>/SignupServlet1</url-pattern>
</servlet-mapping>
</web-app>
if i add login servlet class name and mapping it stops working now I don't know how to fix this pleaseee help!!