Issue
I have a web application in JSP. I made a computer change and migrated my eclipse project to the new computer. In the old one I had Tomcat 9, now I have Tomcat 10. I did not make any changes to the code when I sent everything to the new computer.
When I run my application and search for the first servlet, it cannot find it, it sends me an error:
HTTP Status 404 - Not Found
Status report type
message The required resource [/WebProject/LoginServlet] is not available
Description The required resource is not available.
Apache Tomcat/10.0.2
It is worth mentioning that I do not use the implementation descriptor, I use the annotations with the @WebServlet
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Servlet implementation class LoginServlet
*/
@SuppressWarnings("serial")
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
...my content...
}
I rewrote a part of the application in another test project because I thought that maybe something would change between version 9 and 10 of Tomcat, however the result is the same. Although it seems that I have to define where it will take the servlets by default when using an annotation, I'm not sure where I can configure that.
Anyone who can help or guide me with this problem?
Solution
You have the same problem as in this question, although you have different symptoms.
Tomcat implements standards from Jakarta EE 9, which for copyright reasons has a very breaking change: all APIs changed namespace from javax.*
to jakarta.*
. You server scans the classpath for jakarta.servlet.WebServlet
annotations, so it ignores your javax.servlet.WebServlet
annotation.
You have one of two solutions:
- keep using Tomcat 9: I believe it will be supported for a very long time, as well as all libraries that use the
javax.*
prefix, - replace in Eclipse the runtime you are coding against with Tomcat's 10 and update the prefixes of the imported classes. There is also a migration tool that does it for you.
Answered By - Piotr P. Karwasz