0

When I create a web application project in IntelliJ IDEA and start the template application, the initial page loads up, however when I click on the 'Hello servlet' link, it leads me to a page which says:

Type Status Report

Description The origin server did not find a current representation
for the target resource or is not willing to disclose that one exists.

This is the HelloServlet:

package com.example.exampleweb;

import java.io.*;
import javax.servlet.http.*;
import javax.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() {
    }
}

and my index.jsp looks like:

<%@ 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>

I am on an M1 MacBook Pro, and I'm using Java 11 (Azul-11) and Tomcat 10.0.16

My project structure: My project structure looks like this

ninesw
  • 25
  • 6

0 Answers0