0

When I try to follow the link in index.jsp to HelloServlet, 404 error appears and when I created a new servlet, any links to one doesn't work too.

index.jsp:

    <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <title>JSP - Hello World</title>
</head>
<body>
<h1><%= "Hello World!" %>
</h1>
<br/>
<a href="hello-servlet">Hello Servlet</a>
</body>
</html>

HelloServlet class:

package by.bsac.laboratorywork1;

import java.io.*;

import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

@WebServlet("/hello-servlet")
public class HelloServlet extends HttpServlet {
    private String message;

    public void init() {
        message = "Hello World!";
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html");

        // Hello
        PrintWriter out = response.getWriter();
        out.println("<html><body>");
        out.println("<h1>" + message + "</h1>");
        out.println("</body></html>");
    }

    public void destroy() {
    }
}

Project structure:

enter image description here

Here is info about the error:

enter image description here

Also, links to jsp-pages don't work.

Popnoodles
  • 28,090
  • 2
  • 45
  • 53
  • 1
    Please have a look here: https://stackoverflow.com/questions/11731377/servlet-returns-http-status-404-the-requested-resource-servlet-is-not-availa – slindenau Aug 17 '22 at 12:36
  • Does this answer your question? [Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available"](https://stackoverflow.com/questions/11731377/servlet-returns-http-status-404-the-requested-resource-servlet-is-not-availa) – Popnoodles Aug 17 '22 at 15:16
  • 1
    You cannot use Jakarta Servlet with Tomcat 8. You need Tomcat 10 – jan.supol Aug 18 '22 at 20:41

0 Answers0