I have a Java web application which is working perfectly when launched via eclipse's "run in server" menu option, but when I deploy the war file to tomcat running on a VPS it gives a 404 error when trying to access any of the servlets (there is one servlet that's working but I have no idea why it would work and the others wouldn't). All the jsp documents and directly served files are also working fine, it's just the servlets that I can't get to work.
I had originally been using @WebServlet
annotations, but I deleted them and I'm using web.xml because the server I'm deploying to seems to ignore the annotations, that may have been a waste of time.
This is my 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>
/check is the servlet that's working properly, but all the other servlet mappings just lead to the 404 error page. Once again: the entire web app is working fine on my local machine, just not on the remote server, even though they ostensibly have the same version of tomcat 7.
I have no idea why this worked:
Problem solved.
For Tomcat as well as JBoss, if there are strange errors, it can help to clear the 'temp' and 'work' folders. At my work, us dev's have a batch script to clear those folders on server start.