当前位置: 首页 > 知识库问答 >
问题:

HTTP状态404错误或web.xml错误不知道

强德厚
2023-03-14

我正在Eclipse中运行tomcat 7...我得到以下错误当我运行我的html调用一个servlet来执行一个简单的计算…错误为

HTTP Status 404 - /TestTomcat/  
--------------------------------------------------------------------------------

type Status report  
message /TestTomcat/
description The requested resource is not available.

--------------------------------------------------------------------------------
Apache Tomcat/7.0.37

我的html文件是

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <form method="post" action="http://localhost:8080/TestTomcat/">
        What's your name <br />
        <input name="yourname" value="Test"/><br />

        First number <br />
        <input name="firstnum" value="3" /><br />

        Second number<br />
        <input name="secondnum" value="5"/><br />

        <input type="hidden" name="Language" value="English" />

        <input type="submit" />

    </form>
</body>
</html>
package helloServlets;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/TestTomcat")
public class TestTomcat extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

         String usersName = request.getParameter("yourname");

         String theLang = request.getParameter("Language");

         int firstNum = Integer.parseInt(request.getParameter("firstnum"));
         int secondNum = Integer.parseInt(request.getParameter("secondnum"));
         int sumONum = firstNum + secondNum;
         response.setContentType("text/html");

         PrintWriter output = response.getWriter();

         output.println("<html><body><h3>Hello " + usersName);

         output.println("</h3><br />" + firstNum + " + " + secondNum);
         output.println(" = " + sumONum + "<br />Speaks " + theLang + "</body></html>");
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

}
<?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_3_0.xsd" id="WebApp_ID" version="3.0">
   <display-name>Student_database</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-name>TestTomcat</servlet-name>
        <servlet-class>helloServlets.TestTomcat</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>TestTomcat</servlet-name>
        <url-pattern>/TestTomcat</url-pattern>
    </servlet-mapping>
</web-app>

我以前做过,但当我启动服务器时,我得到以下错误

Mar 03, 2013 9:56:29 AM org.apache.catalina.core.AprLifecycleListener init
INFO: 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 (x86)\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jre7/bin/client;C:/Program Files (x86)/Java/jre7/bin;C:/Program Files (x86)/Java/jre7/lib/i386;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Java\jdk1.7.0_15\bin;C:\Program Files\eclipse;;.
Mar 03, 2013 9:56:29 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:TomcatTest' did not find a matching property.
Mar 03, 2013 9:56:29 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Mar 03, 2013 9:56:29 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Mar 03, 2013 9:56:29 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 502 ms
Mar 03, 2013 9:56:29 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Mar 03, 2013 9:56:29 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.37
Mar 03, 2013 9:56:30 AM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/TomcatTest]]
    at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
    at java.util.concurrent.FutureTask.get(Unknown Source)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/TomcatTest]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    ... 7 more
Caused by: java.lang.IllegalArgumentException: The servlets named [TestTomcat] and [helloServlets.TestTomcat] are both mapped to the url-pattern [/TestTomcat] which is not permitted
    at org.apache.catalina.deploy.WebXml.addServletMapping(WebXml.java:335)
    at org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet(ContextConfig.java:2412)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2125)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2080)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2073)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1300)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:369)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5179)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 7 more

Mar 03, 2013 9:56:30 AM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
    at java.util.concurrent.FutureTask.get(Unknown Source)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:684)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:456)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 7 more

Mar 03, 2013 9:56:30 AM org.apache.catalina.startup.Catalina start
SEVERE: Catalina.start: 
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:684)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:456)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 11 more

Mar 03, 2013 9:56:30 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 490 ms

共有1个答案

丌官淇
2023-03-14

尝试将注释更改为@webservlet(name=“testtomcat”,urlPatterns={“/testtomcat”})并从web.xml中删除任何servlet映射。我希望它能奏效。

 类似资料:
  • 如何在SpringMVC中实现自定义http错误处理。 例如:我有一个urlhttp://localhost:8080/demo/canvas 它显示我的画布页面,但如果用户错过了网址并键入http://localhost:8080/demo/canva 它显示了Tomcat呈现的HTTP状态404。我希望它是自定义jsp页面。

  • 这是我在SpringMVC中使用Maven的第一个应用程序。下面是应用程序结构。 控制器代码: 当我点击index.jsp中的链接时,页面应该被遍历到helloworld.jsp

  • 虽然我精通Java,但我对使用maven开发web应用完全陌生,我正在努力创建一个简单的HelloWorld servlet应用——我正在使用Eclipse Mars和Tomcat 8。 我添加了一个简单的servlet,它应该打印出“hello world”,但是当我尝试使用url模式运行servlet时(所以<代码>http://localhost:8080/MyApp/HelloWorld我

  • 我正在尝试创建我的第一个servlet,但我得到了404状态代码。 web.xml 你好Java语言 我想运行它:localhost:8080/hello 现在它的状态是404 "说明源服务器没有找到目标资源的当前表示形式,或者不愿意透露目标资源的存在。" 我怎样才能解决这个问题?

  • 你好,我刚到这个迷人的r世界,我没有能够跳过不存在的网址,我该如何处理呢?不要标为和错误,谢谢你的帮助。

  • 问题内容: 我有2 ng-包括HTML。考虑服务器中是否不存在ng-include src之一。截至目前,它只会加载空白html,并且在浏览器控制台中会显示未找到http-404文件。 因此,在这种情况下,我只想将默认错误页面(服务器中存在)加载到该特定div中,即一半显示默认错误页面,另一部分显示通过nginclude加载的正确div。 我的逻辑是,使用HTTP拦截器拦截所有HTTP调用。无论何