我有一个Java Web应用程序,当通过eclipse的“运行在服务器”菜单选项启动时工作正常,但是当我将war文件部署到运行在VPS上的tomcat时,它在尝试访问任何一个时出现404错误servlets(有一个servlet正在工作,但我不知道它为什么会起作用,而其他的则不行)。所有的jsp文档和直接提供的文件也都运行正常,它只是我无法工作的servlet。
我最初使用的是@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>
/ check是正常工作的servlet,但所有其他servlet映射只会导致404错误页面。再一次:整个网络应用程序在我的本地计算机上工作正常,而不是在远程服务器上,即使它们表面上具有相同版本的tomcat 7。
答案 0 :(得分:1)
对于Tomcat和JBoss,如果有奇怪的错误,它可以帮助清除“临时”。和&#39;工作&#39;文件夹。在我的工作中,我们开发人员有一个批处理脚本来清除服务器启动时的那些文件夹。
答案 1 :(得分:0)
我不知道为什么会这样:
sudo apt-get purge tomcat7
sudo apt-get install tomcat7
问题解决了。