简体   繁体   English

Tomcat 上的 Java servlets 出现 404 错误,但在本地主机上工作正常

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

I have design a webApp with NetBeans IDE.我设计了一个带有 NetBeans IDE 的 webApp。 It works fine on localhost, but when I deploy it on my host, trying to access the servlets give me a 404 error.它在 localhost 上运行良好,但是当我在主机上部署它时,尝试访问 servlets 给我一个 404 错误。

My servlet dos include the URLpattern and the Name specifications, like this我的 servlet 包括 URLpattern 和 Name 规范,像这样

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

The servlet just does a "redirection" to a.jsp servlet 只是“重定向”到 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).如果我使用 URL www.mysite/faq.jsp 它可以正常工作,但是当我尝试 servlet www.mysite/faq 时它不会(即使它在 localhost 上也可以,正如我所说)。

I have checked the.class files are compiled and included on the WEB-INF folder and it doesn't seme to be the problem.我检查了 .class 文件已编译并包含在 WEB-INF 文件夹中,这似乎不是问题。

Also I tried to add the web.xml description of the servlet like below, but it doesn't work either.我还尝试添加如下 servlet 的 web.xml 描述,但它也不起作用。

<?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.谢谢你们。

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.托管服务器是在 Tomcat 10x 和 JDK 10 上配置的,而我的项目是在 jdk 8 和 tomcat 7 上构建的。解决方案是询问托管服务提供商并更改服务器配置以适合我的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ubuntu14.04 html 上的 Tomcat7 可以工作,但 servlet 出现 404 错误 - Tomcat7 on Ubuntu14.04 html works but 404 error for servlets Tomcat通过Servlet给出404错误 - Tomcat giving 404 error with servlets 自定义servlet在Tomcat 6上提供404,在7上运行良好 - Custom servlet gives 404 on Tomcat 6, works fine on 7 Java Servlet的Http 404/500错误? - Http 404/500 error with Java servlets? 使用ip地址访问本地应用程序时出现404错误,但在localhost下可以正常工作吗? - Getting 404 error when access local application with ip address but works fine with localhost? 在 Eclipse Tomcat 服务器中抛出“HTTP 状态 404 – 未找到”错误,因为它适用于 Mozilla 浏览器? - “HTTP Status 404 – Not Found” error is throws in Eclipse Tomcat server, as it works fine for Mozilla browser? 使用Servlet时的Tomcat 404 - Tomcat 404 when using servlets Tomcat7(localhost:8080):404错误 - Tomcat7 (localhost:8080): 404 error HTTP 404 Java Servlet - HTTP 404 Java Servlets 相同的 .war 文件,没有 .xml 配置 Spring MVC 应用程序与 Tomcat9。 在 localhost:8080 上运行良好,远程服务器出现 404 错误 - Same .war file with no .xml configuration Spring MVC app with Tomcat9. Running fine at localhost:8080, I got 404 error in Remote server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM