1

I have deployed my application (todo.war) into Tomcat v10.0.5. I expected that http://localhost:8080/todo/ would bring me to /jsp/index.jsp, but I am getting a 404 response instead.

Here is my application's layout:

todo.war
├── META-INF
│   └── MANIFEST.MF
├── WEB-INF
│   ├── classes
│   │   └── com
│   │       └── ciaoshen
│   │           └── sia
│   │               └── demo
│   │                   └── gradle_demo
│   │                       └── todo
│   │                           ├── model
│   │                           │   └── ToDoItem.class
│   │                           └── web
│   │                               └── ToDoServlet.class
│   ├── lib
│   │   └── jstl-1.2.jar
│   └── web.xml
├── css
└── jsp
    ├── all.jsp
    └── index.jsp

So in web.xml file, servlet-mapping pattern / is bound to ToDoServlet,

<servlet-mapping>
    <servlet-name>ToDoServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

and ToDoServlet.java dispatched the path / to /jsp/index.jsp file.

private String processRequest(String servletPath, HttpServletRequest request) {
    if (servletPath.equals("/")) {
        return "/jsp/index.jsp";
    } else if (servletPath.equals("/all")) {
        // ... other direction
    } else {
        // ... other direction
    }
} 

but got 404 resource not found in browser, enter image description here

my index.jsp is very simple,

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html>
<head><title>First JSP</title></head>
<body>
    <h2>--- To Do Application ---</h2>
    <h2>Please make a choice:</h2>
    <h2><a href="/all">    (a)ll items</a></h2>
</body>
</html>

Can someone explain what I'm missing?

Christopher Schultz
  • 20,221
  • 9
  • 60
  • 77
shen
  • 933
  • 10
  • 19
  • 1
    Since you are using Tomcat 10, are you using Servlet 5.0 (the classes, which start with `jakarta.servlet` instead of `javax.servlet`)? Check the logs for messages as in [this question](https://stackoverflow.com/q/64117697/11748454). – Piotr P. Karwasz Apr 28 '21 at 03:34
  • @PiotrP.Karwasz problem solved when I switch dependencies to `jakarta.servlet:jakarta.servlet-api:5.0.0`. Thanks man! – shen Apr 28 '21 at 04:51
  • @BalusC This is not a duplicate due to the nature of the problem. – Christopher Schultz Apr 28 '21 at 21:34
  • @PiotrP.Karwasz Make your comment into an answer; I believe it is the correct one and should be accepted. – Christopher Schultz Apr 28 '21 at 21:35
  • @ChristopherSchultz: I also believe this question to be a duplicate (of all those questions caused by the jakartification process). If we consider duplicates two questions with the same symptoms, I tried to list 4 prototype duplicates in [this answer](https://stackoverflow.com/a/66808062/11748454). The closest question to this one is probably _"X is not a jakarta.servlet.Servlet"_. – Piotr P. Karwasz Apr 28 '21 at 22:34

0 Answers0