Servers运行不成功

Servers运行不成功

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>FirstServlet</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 -->
  <servlet>
  <!-- servlet的别名 -->
  <servlet-name>first</servlet-name>
  <servlet-class>com.imooc.servlet.FirstServlet</servlet-class>
  </servlet>
  <!-- 将Servlet与URL绑定 -->
  <servlet-mapping>
  <servlet-name>first</servlet-name>
  <url-pattern>/hi</url-pattern>
  </servlet-mapping>
</web-app>

是不是路径问题啊?感觉有点乱

package com.imooc.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//HttpServlet是所有小程序的父类,必须继承
public class FirstServlet extends HttpServlet{
// Servlet方法的重写
 @Override
 protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//  结束请求发来的参数
  String name=request.getParameter("name");
  String html="<h1 style='color:red'>hi,"+name+"!</h1><hr/>";
  System.out.println("返回给浏览器的响应数据为:"+html);
  PrintWriter out=response.getWriter();//从服务器向浏览器返回的输出流
  out.println(html);//将html发送回浏览器
 }

}

四月 27, 2019 7:33:06 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server version:        Apache Tomcat/8.5.40
四月 27, 2019 7:33:06 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server built:          Apr 10 2019 14:31:19 UTC
四月 27, 2019 7:33:06 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server number:         8.5.40.0
四月 27, 2019 7:33:06 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Name:               Windows 10
四月 27, 2019 7:33:06 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Version:            10.0
四月 27, 2019 7:33:06 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Architecture:          amd64
四月 27, 2019 7:33:06 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Java Home:             C:\Program Files\Java\jdk1.8.0_121\jre
四月 27, 2019 7:33:06 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Version:           1.8.0_121-b13
四月 27, 2019 7:33:06 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Vendor:            Oracle Corporation
四月 27, 2019 7:33:06 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_BASE:         D:\Dom4j\apache-tomcat-8.5.40
四月 27, 2019 7:33:06 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_HOME:         D:\Dom4j\apache-tomcat-8.5.40
四月 27, 2019 7:33:06 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:61628
四月 27, 2019 7:33:06 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -javaagent:D:\java\eclipse\configuration\org.eclipse.osgi\409\0\.cp\lib\javaagent-shaded.jar
四月 27, 2019 7:33:06 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.base=D:\Dom4j\apache-tomcat-8.5.40
四月 27, 2019 7:33:06 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.home=D:\Dom4j\apache-tomcat-8.5.40
四月 27, 2019 7:33:06 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dwtp.deploy=D:\Dom4j\apache-tomcat-8.5.40\webapps
四月 27, 2019 7:33:06 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.endorsed.dirs=D:\Dom4j\apache-tomcat-8.5.40\endorsed
四月 27, 2019 7:33:06 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dfile.encoding=GBK
四月 27, 2019 7:33:06 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_121\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.8.0_121\jre\bin;C:/Program Files/Java/jdk1.8.0_121/bin/../jre/bin/server;C:/Program Files/Java/jdk1.8.0_121/bin/../jre/bin;C:/Program Files/Java/jdk1.8.0_121/bin/../jre/lib/amd64;C:\Program Files\Java\jdk1.8.0_121\bin\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Users\46215\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Common Files\Autodesk Shared\;D:\HTML安装\command;C:\Program Files (x86)\Autodesk\Backburner\;C:\WINDOWS\System32\OpenSSH\;C:\Users\46215\AppData\Local\Microsoft\WindowsApps;;D:\java\eclipse;;.]
四月 27, 2019 7:33:07 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-nio-8080"]
四月 27, 2019 7:33:08 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
信息: Using a shared selector for servlet write/read
四月 27, 2019 7:33:08 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["ajp-nio-8009"]
四月 27, 2019 7:33:08 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
信息: Using a shared selector for servlet write/read
四月 27, 2019 7:33:08 下午 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 2793 ms
四月 27, 2019 7:33:08 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service [Catalina]
四月 27, 2019 7:33:08 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/8.5.40
四月 27, 2019 7:33:09 下午 org.apache.jasper.servlet.TldScanner scanJars
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
四月 27, 2019 7:33:09 下午 org.apache.jasper.servlet.TldScanner scanJars
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
四月 27, 2019 7:33:09 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory [D:\Dom4j\apache-tomcat-8.5.40\webapps\docs]
四月 27, 2019 7:33:09 下午 org.apache.jasper.servlet.TldScanner scanJars
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
四月 27, 2019 7:33:09 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory [D:\Dom4j\apache-tomcat-8.5.40\webapps\docs] has finished in [177] ms
四月 27, 2019 7:33:09 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory [D:\Dom4j\apache-tomcat-8.5.40\webapps\examples]
四月 27, 2019 7:33:11 下午 org.apache.jasper.servlet.TldScanner scanJars
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
四月 27, 2019 7:33:11 下午 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
四月 27, 2019 7:33:11 下午 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
四月 27, 2019 7:33:11 下午 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: attributeAdded('StockTicker', 'async.Stockticker@6c8ea1c8')
四月 27, 2019 7:33:11 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory [D:\Dom4j\apache-tomcat-8.5.40\webapps\examples] has finished in [1,427] ms
四月 27, 2019 7:33:11 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory [D:\Dom4j\apache-tomcat-8.5.40\webapps\host-manager]
四月 27, 2019 7:33:11 下午 org.apache.jasper.servlet.TldScanner scanJars
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
四月 27, 2019 7:33:11 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory [D:\Dom4j\apache-tomcat-8.5.40\webapps\host-manager] has finished in [164] ms
四月 27, 2019 7:33:11 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory [D:\Dom4j\apache-tomcat-8.5.40\webapps\manager]
四月 27, 2019 7:33:11 下午 org.apache.jasper.servlet.TldScanner scanJars
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
四月 27, 2019 7:33:11 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory [D:\Dom4j\apache-tomcat-8.5.40\webapps\manager] has finished in [121] ms
四月 27, 2019 7:33:11 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory [D:\Dom4j\apache-tomcat-8.5.40\webapps\ROOT]
四月 27, 2019 7:33:11 下午 org.apache.jasper.servlet.TldScanner scanJars
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
四月 27, 2019 7:33:11 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory [D:\Dom4j\apache-tomcat-8.5.40\webapps\ROOT] has finished in [123] ms
四月 27, 2019 7:33:11 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-nio-8080"]
四月 27, 2019 7:33:11 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-nio-8009"]
四月 27, 2019 7:33:11 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in 3080 ms
四月 27, 2019 7:34:51 下午 org.apache.catalina.core.StandardContext reload
信息: Reloading Context with name [/SecondServlet] has started
四月 27, 2019 7:34:51 下午 org.apache.catalina.core.StandardContext reload
严重: Exception starting Context with name [/SecondServlet]
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SecondServlet]]
 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
 at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3828)
 at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:291)
 at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:5608)
 at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1392)
 at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1396)
 at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1396)
 at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1364)
 at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.webresources.StandardRoot@41ec542c]
 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
 at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4885)
 at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5020)
 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
 ... 8 more
Caused by: java.lang.IllegalArgumentException: The main resource set specified [D:\Dom4j\apache-tomcat-8.5.40\webapps\SecondServlet] is not valid
 at org.apache.catalina.webresources.StandardRoot.createMainResourceSet(StandardRoot.java:748)
 at org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:706)
 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
 ... 11 more

四月 27, 2019 7:34:51 下午 org.apache.catalina.core.StandardContext reload
信息: Reloading Context with name [/SecondServlet] is completed
四月 27, 2019 7:38:02 下午 org.apache.catalina.core.StandardContext reload
信息: Reloading Context with name [/FirstServlet] has started
四月 27, 2019 7:38:02 下午 org.apache.catalina.core.StandardContext reload
严重: Exception starting Context with name [/FirstServlet]
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/FirstServlet]]
 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
 at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3828)
 at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:291)
 at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:5608)
 at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1392)
 at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1396)
 at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1396)
 at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1364)
 at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.webresources.StandardRoot@584aa642]
 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
 at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4885)
 at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5020)
 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
 ... 8 more
Caused by: java.lang.IllegalArgumentException: The main resource set specified [D:\Dom4j\apache-tomcat-8.5.40\webapps\FirstServlet] is not valid
 at org.apache.catalina.webresources.StandardRoot.createMainResourceSet(StandardRoot.java:748)
 at org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:706)
 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
 ... 11 more

四月 27, 2019 7:38:02 下午 org.apache.catalina.core.StandardContext reload
信息: Reloading Context with name [/FirstServlet] is completed


正在回答

登陆购买课程后可参与讨论,去登陆

1回答

同学你好!根据报错的信息应该是之前创建的项目还有残留,导致同样名称的项目无法启动,建议同学在自己tomcat的路径下找到server.xml,编辑server.xml文件,找一下之前的配置,删除即可,一般会在文件的最后,大致和如图所示的格式相似

http://img1.sycdn.imooc.com//climg/5cc508c60001aec605740073.jpg

再删除Eclipse左侧Servers中对应的Server.xml文件中多余的<Context>配置

http://img1.sycdn.imooc.com//climg/5cc509150001035e03540170.jpg

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

  • bbb绑绑绑 提问者 #1
    1.“自己tomcat的路径路径下找到server.xml,”是图片中Tomcat v8.0 Server at ...下面的server.xml文件吗? 2.这一步不清楚:"找一下之前的配置,删除即可,一般会在文件的最后,大致和如图所示的格式相似"删哪个配置,是删<Content path=...../>上面所有的东西吗? 注:“删除Eclipse左侧Servers中对应的Server.xml文件中多余的<Context>配置”这一步做了。
    2019-04-28 12:36:55
  • 好帮手慕柯南 回复 提问者 bbb绑绑绑 #2
    同学是你的tomcat的路径下的server.xml,删除文件中多余的<Context>配置,一个是你的安装路径,一个是Eclipse中的,是两步。祝学习愉快~
    2019-04-28 13:06:15
  • bbb绑绑绑 提问者 回复 好帮手慕柯南 #3
    还是没得反应啊,这回什么报错信息都没有@-@
    2019-04-28 17:01:21
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
从网页搭建入门Java Web2018版
  • 参与学习           人
  • 提交作业       1088    份
  • 解答问题       10205    个

如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!

了解课程
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师