简体   繁体   English

每当我添加新的servlet时Tomcat就会停止工作

[英]Tomcat stops working every time i add a new servlet

I'm working on a web app project on eclipse. 我正在Eclipse上进行Web应用程序项目。
I have a weird problem: Every time i try to add a new servlet to my project, when i try to run tomcat I get this error: 我有一个奇怪的问题:每当我尝试向项目中添加新的servlet时,当我尝试运行tomcat时,都会出现此错误:

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

and I'm no more able to run my project. 而且我再也无法运行我的项目了。

this is my web.xml file 这是我的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>

if i delete all my servlet tags this way: 如果我以这种方式删除我所有的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 works and doens't give me that error. tomcat可以工作,并且不会给我该错误。

Either an instance of tomcat is already running (and the 2nd instance can not run due to ports already in use), or there is some error in your configuration preventing tomcat from starting. 要么tomcat实例已在运行(并且第二个实例由于已在使用端口而无法运行),或者您的配置中存在一些错误,导致tomcat无法启动。 You need to look at the tomcat logs to determine the reason. 您需要查看tomcat日志以确定原因。 See "<tomcat_dir>/logs/ " 参见"<tomcat_dir>/logs/

Once I had the same issue and it turned out that I forgot to include / in the url pattern for my servlet. 一旦遇到相同的问题,结果我忘记了在servlet的url模式中包含/ So if you are using annotations for some of your servlets and, for example, you have one of your servlets annotated like this @WebServlet("MyServletSessionContext") instead of @WebServlet("/MyServletSessionContext") and try to deploy it and restart tomcat you will get this error. 因此,如果您对某些servlet使用注释,例如,您的一个servlet像这样@WebServlet("MyServletSessionContext")而不是@WebServlet("/MyServletSessionContext") ,请尝试部署它并重新启动tomcat您将收到此错误。 Make sure that you have / for all your urlPatterns 确保您拥有/所有urlPatterns

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM