samedi 1 mai 2021

When i'm trying to start Standard web app(Java) which is created by Intellij idea(TomcatServer) and go to servlet "url" i get error 404

I'm trying to start web app created by Intellij idea and go to url that should invoke the servlet class i get error 404. I use Apache Tomcat 10.0.5 and have following project structure

Class that named HelloServlet

@WebServlet(name = "helloServlet", value = "/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() {
    }
}

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>

When i'm runnig project i go to url and get what i want enter image description here But if i click on "HelloServlet" that should invoke servlet class i get this error

enter image description here enter image description here

I haven't changed anything in this project




Aucun commentaire:

Enregistrer un commentaire