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 But if i click on "HelloServlet" that should invoke servlet class i get this error
I haven't changed anything in this project
Aucun commentaire:
Enregistrer un commentaire