Destructive Gamer
Destructive Gamer

Reputation: 31

The tomcat server 10.0 server I am using with my keeps showing me an error 404 for the requested resources are not available

When I try to run a simple JSP login form controlled by a servlet in eclipse 2021 and using tomcat server 10.0 , an error 404 keeps popping up on the inbuilt browser window of eclipse for resources not available , but as far as I can comprehend I find the file in the project structure in the root directory too. Here is my code , could someone help me with this please?

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
   pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Login</title>
</head>
<body>
<form action="<%= request.getContextPath()%>/SiteController" method="post">
Username: <input type="text" name="username"> <br/>
Password: <input type="text" name="password"> <br/>
<input type="submit" value="Submit">
</form>
</body>

This is my login.jsp file

package org.saboor.servlets;

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 javax.servlet.http.HttpSession;

/**
 * Servlet implementation class SiteController
 */
@WebServlet("/SiteController")
public class SiteController extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SiteController() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.getWriter().append("Served at: ").append(request.getContextPath());
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username=request.getParameter("username");
        String password=request.getParameter("password");
        if(username.equals("saboor")&& password.equals("baba2011")) {
            request.getSession().invalidate();
            HttpSession newSession=request.getSession();
            newSession.setMaxInactiveInterval(300);
            response.sendRedirect("memberArea.jsp");
        }
        else {
            response.sendRedirect("login.jsp");
        }
    }

}

This is my SiteController.java servlet

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>memberArea</title>
</head>
<body>
memberArea
</body>
</html>

This is the page forward to after successful login.

My Project Structure

Upvotes: 0

Views: 1089

Answers (1)

Ravi K Thapliyal
Ravi K Thapliyal

Reputation: 51711

Your web application depends on the javax.servlet packages, part of the Java EE specification, but Tomcat 10 implements specifications developed as part of Jakarta EE. You should be using Tomcat 9 instead which implements specifications developed as part of Java EE.

From Migration Guide - Tomcat 10.0.x

There is a significant breaking change between Tomcat 9.0.x and Tomcat 10.0.x. The Java package used by the specification APIs has changed from javax.** to jakarta.** It will be necessary to recompile web applications against the new APIs.

If you must use Tomcat 10, you'll have to update all your package references as well as switch all your dependencies (like, servlet-api, jsp-api, jstl, etc.) to library versions that conform to the new Jakarta EE specifications.

Another option is to use the Apache Tomcat migration tool for Jakarta EE.

Tomcat can convert an existing web application from Java EE 8 to Jakarta EE 9 at deployment time using the Apache Tomcat migration tool for Jakarta EE.

To make use of the feature, the web application should be placed in the legacyAppBase folder (by default named webapps-javaee) and they will be converted to an equivalent Jakarta EE web application in the appBase folder (by default named webapps).

But, migrations can bring their own set of challenges, so, your mileage may vary here.

Upvotes: 2

Related Questions