我有一個Java web應用程序,它在通過eclipse的「run in server」菜單選項啓動時運行完美,但是當我部署war文件對於運行在VPS上的tomcat,當試圖訪問任何servlet時(有一個servlet正在工作,但我不知道爲什麼它可以工作,其他人不會),它會產生404錯誤。所有的jsp文檔和直接提供的文件也工作正常,這只是我無法工作的servlet。Tomcat 7部署的戰爭:Servlets上的404錯誤,其他文件很好,日食中的一切都很好
我原本一直在使用@WebServlet
註解,但我刪除了它們,我使用的是web.xml,因爲我正在部署的服務器似乎忽略了註釋,這可能是浪費時間。
這是我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<!-- 30天內自動登錄(檢測COOKIE) -->
<filter>
<filter-name>loginFilter</filter-name>
<filter-class>co.fsjr.web.LoginCookie</filter-class>
</filter>
<filter-mapping>
<filter-name>loginFilter</filter-name>
<url-pattern>/main.jsp</url-pattern>
</filter-mapping>
<filter>
<filter-name>adminFilter</filter-name>
<filter-class>co.fsjr.web.AdminIntercept</filter-class>
</filter>
<filter-mapping>
<filter-name>adminFilter</filter-name>
<url-pattern>/user/adminuser/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>ActionServlet</servlet-name>
<servlet-class>co.fsjr.web.ActionServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>CheckCode</servlet-name>
<servlet-class>co.fsjr.util.CheckCode</servlet-class>
</servlet>
<servlet>
<servlet-name>FlightQuery</servlet-name>
<servlet-class>co.fsjr.servlet.FlightQuery</servlet-class>
</servlet>
<servlet>
<servlet-name>AdminUserServlet</servlet-name>
<servlet-class>co.fsjr.servlet.AdminUserServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>FlightSortServlet</servlet-name>
<servlet-class>co.fsjr.servlet.FlightSortServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>OrderServlet</servlet-name>
<servlet-class>co.fsjr.servlet.OrderServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>PrepareDataServlet</servlet-name>
<servlet-class>co.fsjr.servlet.PrepareDataServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>PayPalServlet</servlet-name>
<servlet-class>co.fsjr.servlet.PayPalServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>UserServlet</servlet-name>
<servlet-class>co.fsjr.servlet.UserServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ActionServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CheckCode</servlet-name>
<url-pattern>/check</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FlightQuery</servlet-name>
<url-pattern>/FlightQuery</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AdminUserServlet</servlet-name>
<url-pattern>/AdminUserServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FlightSortServlet</servlet-name>
<url-pattern>/FlightSortServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>OrderServlet</servlet-name>
<url-pattern>/OrderServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>PayPalServlet</servlet-name>
<url-pattern>/PayPalServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>PrepareDataServlet</servlet-name>
<url-pattern>/PrepareDataServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>UserServlet</servlet-name>
<url-pattern>/UserServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/main.jsp</welcome-file>
</welcome-file-list>
<!-- 配置錯誤處理 -->
<error-page>
<error-code>404</error-code>
<location>/error/404.jsp</location>
</error-page>
<error-page>
<error-code>505</error-code>
<location>/505.html</location>
</error-page>
<!-- 配置異常處理 -->
<error-page>
<exception-type>javax.servle.ServletException</exception-type>
<location>/errorpage.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>/error.html</location>
</error-page>
</web-app>
/檢查是運作正常的servlet,但所有其他的servlet映射只是導致404錯誤頁面。再次:整個Web應用程序工作正常,我的本地機器上,只是沒有在遠程服務器上,即使他們表面上擁有的tomcat相同版本的7
'Check'和其他servlet在同一個目錄下? –
用於檢查的servlet位於/ WEB-INF/classes/co/fsjr/util中,另一個位於/ WEB-INF/classes/co/fsjr/servlet中。但是包前綴是正確的,所以不應該是問題。 –