1

I currently have issues trying to access /registerForm in my web servlet, the server I'm using is tomcat 9, java 11 and Eclipse as my IDE. I have created a Register page, a register servlet and a DAO. Right now registerForm.jsp works but not the servlet. Current error msg: The requested resource [/Java_Web_Project/registerForm] is not available

Project Structure - https://i.stack.imgur.com/onE0Z.png

I have tried to follow solutions from other post, but it didnt quite work for me, i have put all the servlets under one package as shown in the project structure.

UserRegisteredServlet.java

@WebServlet("/registerForm")
public class UserRegisterServlet extends HttpServlet{
    
    public @interface WebServlet{
        
    }
    
    private static final long serialVersionUID = 1L;
    
    public UserRegisterServlet() {
        super();
    }
    
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        
        UserDAO userDAO = new UserDAO();
        
        try {
            userDAO.createUsers(username, password);
            String destPage = "registerForm.jsp";
            
            System.out.println("Success");
            RequestDispatcher dispatcher = request.getRequestDispatcher(destPage);
            dispatcher.forward(request, response);
            
            
        }catch(SQLException | ClassNotFoundException ex) {
            throw new ServletException(ex);
        }
        
    }
    
}

RegisterForm.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>ID Registration</title>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  crossorigin="anonymous"></script>
<script type="text/javascript"
    src="https://cdn.jsdelivr.net/npm/jquery-validation@1.19.0/dist/jquery.validate.min.js"></script>
<link href=”bootstrap/css/bootstrap.min.css” rel=”stylesheet” type=”text/css” />
<script type=”text/javascript” src=”bootstrap/js/bootstrap.min.js”></script>
</head>
<body>
    <div style='text-align=center' class="container">
    <h1>ID Registration</h1>
        <form action='${pageContext.request.contextPath}/registerForm' method='POST' role='form'>
        <div class='registerform'>
            <label for='username'> Username: </label>
            <input type="text" placeholder='Username' class='form-control' name='username'>
        </div>
        <div class='registerform'>  
            <label for='password'> Password: </label>
            <input type="password" class='form-control' placeholder='Password' name='password'>
        </div>
            <br><br>
            <button type="submit" class="btn btn-default"> Register </button>
        </form>
    </div>
    
</body>
</html>

I dont have a web xml because Im not using Tomcat v6 or lower.

Solutions from the other post doesnt work for me.

Anon1234
  • 23
  • 5

1 Answers1

0

The 404 response means that at the location you requested no page/servlet was found. This can mean anything between you do not have a servlet on that path up to the application is not deployed. Check your Tomcat logfiles to get some more hints.

Queeg
  • 7,748
  • 1
  • 16
  • 42
  • well i didnt have tomcat installed fyi, so there isnt a log file created. – Anon1234 Jan 25 '22 at 08:04
  • Mind your own statement: 'server I'm using is tomcat 9, java 11' – Queeg Jan 25 '22 at 11:17
  • I downloaded the zip file btw & im using eclipse IDE, so i just add external libraries via eclipse and run it from there, no log file is generated inside the tomcat log server that i can usually find, under program files/tomcat because that directory dont exist. – Anon1234 Jan 26 '22 at 01:37
  • so how do I get to the tomcat log files in eclipse? – Anon1234 Jan 26 '22 at 01:39