Java servlets on Tomcat take to 404 error but it works fine on localhost

Tags: , , ,



I have design a webApp with NetBeans IDE. It works fine on localhost, but when I deploy it on my host, trying to access the servlets give me a 404 error.

My servlet dos include the URLpattern and the Name specifications, like this

@WebServlet(name = "FAQ", urlPatterns = {"/faq"})
public class FAQ extends HttpServlet {

The servlet just does a “redirection” to a .jsp

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.getRequestDispatcher("/faq.jsp").forward(request, response);
        
    }

If I use the URL www.mysite/faq.jsp it works ok, but it doesn’t when I try the servlet www.mysite/faq (even it does on localhost, as I said).

I have checked the .class files are compiled and included on the WEB-INF folder and it doesn’t seme to be the problem.

Also I tried to add the web.xml description of the servlet like below, but it doesn’t work either.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <servlet>
        <servlet-name>FAQ</servlet-name>
        <servlet-class>beans.FAQ</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>FAQ</servlet-name>
        <url-pattern>/faq</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
</web-app>

I don’t know waht could be my problem and it may be a very stupid thing, but I can’t find it.

Thank you all.

Answer

SOLVED:

As I said, it should be a simple thing. The hosting server was configurated on Tomcat 10x and JDK 10, while my project was build on jdk 8 and tomcat 7. The solution was to ask for the hosting provider and change the server configuration to fit my project.



Source: stackoverflow