I'm a new javaer. I am trying to develop a webapplication and deploy in tomcat. I just use the template created by idea, but it works not well.
I'm using tomcat9.0.41.
HelloServlet.java
import java.io.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
@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() {
}
}
when I open http://localhost:8080/serv01_war_exploded/ in chrome, it works well and shows the content in index.jsp. But when I try to open http://localhost:8080/serv01_war_exploded/hello-servlet, it returns 404 error.
All the above happens in windows10 system.
So what caused this problem, idea or tomcat or some other things?