[英]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.