Java servlet tomcat 404

时间:2017-02-13 11:56:10

标签: java apache tomcat servlets

您好我在尝试使用tomcat servlet,但我使用app ache tomcat 9.0创建了一个动态Web项目,servlet和服务器。

我已经尝试了几乎每一个答案,但我一直没有运气。

type Status report

message /OOSSP1/hello

description The requested resource is not available.

CONSOLE.LOG

Feabh 13, 2017 11:47:24 A.M. org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:OOSSP1' did not find a matching property.
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/9.0.0.M17
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Jan 10 2017 20:59:20 UTC
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         9.0.0.0
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Windows 10
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            10.0
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             C:\Program Files\Java\jre1.8.0_121
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.8.0_121-b13
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         E:\Documents\Development\Projects\College\.metadata\.plugins\org.eclipse.wst.server.core\tmp3
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         E:\Program Files (x86)\Tomcat\apache-tomcat-9.0.0.M17\apache-tomcat-9.0.0.M17
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=E:\Documents\Development\Projects\College\.metadata\.plugins\org.eclipse.wst.server.core\tmp3
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=E:\Program Files (x86)\Tomcat\apache-tomcat-9.0.0.M17\apache-tomcat-9.0.0.M17
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=E:\Documents\Development\Projects\College\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=E:\Program Files (x86)\Tomcat\apache-tomcat-9.0.0.M17\apache-tomcat-9.0.0.M17\endorsed
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.core.AprLifecycleListener lifecycleEvent
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\Java\jre1.8.0_121\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_121/bin/server;C:/Program Files/Java/jre1.8.0_121/bin;C:/Program Files/Java/jre1.8.0_121/lib/amd64;C:\Program Files (x86)\Google\Chrome\Application;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)\NVIDIA Corporation\PhysX\Common;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\Git\cmd;C:\Users\alexi\.windows-build-tools\python27;C:\Program Files\Java\jdk1.8.0_111;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Windows\system32\config\systemprofile\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Java\jdk1.8.0_111\bin;C:\Program Files\Java\jdk1.8.0_111\bin;E:\Documents\Development\Projects\OOP3_Project1\bin\application;E:\Documents\Development\Projects\OOP3_Project1\src\application;E:\Program Files (x86)\PuTTY\;C:\HashiCorp\Vagrant\bin;C:\Program Files\nodejs\;C:\Ruby23-x64\bin;C:\Users\alexi\AppData\Local\Microsoft\WindowsApps;C:\Users\alexi\AppData\Local\.meteor\;C:\Users\alexi\.windows-build-tools\python27;E:\Documents\Development\Projects\OOP3_Project1\bin\application;E:\Documents\Development\Projects\OOP3_Project1\src\application;C:\Users\alexi\AppData\Roaming\npm;E:\Downloads;;.
Feabh 13, 2017 11:47:24 A.M. org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Feabh 13, 2017 11:47:24 A.M. org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Feabh 13, 2017 11:47:24 A.M. org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Feabh 13, 2017 11:47:24 A.M. org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 518 ms
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/9.0.0.M17
Feabh 13, 2017 11:47:24 A.M. org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [http-nio-8080]
Feabh 13, 2017 11:47:24 A.M. org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [ajp-nio-8009]
Feabh 13, 2017 11:47:24 A.M. org.apache.catalina.startup.Catalina start
INFO: Server startup in 236 ms

HelloServlet.java

package ie.cit.oossp;

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

/**
 * Servlet implementation class HelloServlet
 */
@WebServlet({ "/HelloServlet", "/hello" })
public class HelloServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public HelloServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.getWriter().append("Served at: ").append(request.getContextPath());
    }

}

我对此非常陌生,但我不明白这是多么困难让我疯狂。

任何帮助都会很棒。

1 个答案:

答案 0 :(得分:-1)

您必须将您的servlet映射到web.xml文件中。 你是否? 如果没有将这些行添加到您的文件中:

    <servlet>
      <servlet-name>watermelon</servlet-name>
      <servlet-class>myservlets.watermelon</servlet-class>
    </servlet>