【问题标题】:Tomcat stops working every time i add a new servlet每次我添加一个新的 servlet 时,Tomcat 都会停止工作
【发布时间】:2013-10-24 12:51:58
【问题描述】:

我正在 Eclipse 上开发一个网络应用项目。
我有一个奇怪的问题:每次我尝试向我的项目添加一个新的 servlet 时,当我尝试运行 tomcat 时,我都会收到此错误:

Server Tomcat v7.0 Server at localhost failed to start.

我无法再运行我的项目了。

这是我的 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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Jeans4</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

  <servlet>
    <description></description>
    <display-name>prova</display-name>
    <servlet-name>prova</servlet-name>
    <servlet-class>Jeans.prova</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>prova</servlet-name>
    <url-pattern>/prova</url-pattern>
  </servlet-mapping>

  <servlet>
    <description></description>
    <display-name>FileUploadDBServlet</display-name>
    <servlet-name>FileUploadDBServlet</servlet-name>
    <servlet-class>Jeans.FileUploadDBServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>FileUploadDBServlet</servlet-name>
    <url-pattern>/FileUploadDBServlet</url-pattern>
  </servlet-mapping>

  <servlet>
    <description></description>
    <display-name>BlobDisplay</display-name>
    <servlet-name>BlobDisplay</servlet-name>
    <servlet-class>Jeans.BlobDisplay</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>BlobDisplay</servlet-name>
    <url-pattern>/BlobDisplay</url-pattern>
  </servlet-mapping>



</web-app>

如果我以这种方式删除我所有的 servlet 标记:

<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.coma/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Jeans4</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list> 
</web-app>

tomcat 可以正常工作并且不会给我这个错误。

【问题讨论】:

  • 这是您添加到 web.xml 的确切 xml 吗?如果是这样,您需要添加一个打开的 标记。此外,如果您需要添加有关 servlet 的注释,请删除描述元素并使用 xml cmets。

标签: java jsp servlets


【解决方案1】:

要么一个 tomcat 实例已经在运行(并且第二个实例由于端口已经在使用中而无法运行),或者你的配置中有一些错误阻止 tomcat 启动。您需要查看 tomcat 日志以确定原因。见"&lt;tomcat_dir&gt;/logs/"

【讨论】:

  • 我尝试重新启动计算机,但我遇到了同样的问题。这就是为什么我不明白为什么有 r 2 个 tomcat 实例不管怎样,每次我添加一个新的 servlet 时都会发生这种情况。我试图查看日志;在那个目录里面我有很多日志,但没有一个是最新的。最新的日志文件是 10 月 18 日写的。今天什么都没写
  • 你是如何启动tomcat服务器的?从命令提示符还是 eclipse?
  • 从 Eclipse,当我运行我的项目时。我总是这样做。但有时它会停止工作,我会花费数小时试图找到解决方案。此外,一次有效的解决方案将不会在另一次有效。似乎每次出现此类问题的原因都不同
  • 你需要弄清楚你的tomcat安装在哪里运行并找到日志输出。 Tomcat 总是会在启动时将一些输出写入日志。 Tomcat 日志记录可能已被禁用/重定向,但这在独立运行 Tomcat 或从 Eclipse 中运行时并不常见。也许您有多个 Tomcat 安装?或者您可能将 Tomcat 作为服务安装,因此当您重新启动计算机时它已经在运行,从而阻止您的开发实例启动?
  • 你能在eclipse之外运行tomcat吗?这可能对您更可靠,并帮助您解决问题。在任何情况下,您都需要简化,然后提供更多信息,以获得任何有用的帮助。
【解决方案2】:

一旦我遇到了同样的问题,结果发现我忘记在我的 servlet 的 url 模式中包含 /。因此,如果您正在为某些 servlet 使用注释,例如,您有一个 servlet 被注释为 @WebServlet("MyServletSessionContext") 而不是 @WebServlet("/MyServletSessionContext") 并尝试部署它并重新启动 tomcat,您将收到此错误。确保所有 urlPatterns 都有 /

【讨论】:

    【解决方案3】:

    如果你使用过Eclipse或者Spring Tool Suite,并且在Servlet定义(java类)中使用了注解@WebServlet,那么你在调用Servlet的时候一定要把项目名作为上下文路径。 例如:我的 servlet 是 @WebServlet(name="Employee",value="/Employee") 公共类 Employee 扩展 HttpServlet {...}

    而我的项目(模块)名称是 JSP_Project,那么您应该将此值写入表单标签中的 action 属性或 ajax 中的 url 属性中:

    . 或者 url:'/JSP_Project/Employee' 而已。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-22
      • 1970-01-01
      相关资源
      最近更新 更多