Tomcat 404 en servlet Java

user1357015:

Estoy tratando de seguir el tutorial aquí https://tcserver.docs.pivotal.io/3x/docs-tcserver/topics/tutwebapp.html#tutwebapp-ant-buildfiley construir mi primera aplicación Tomcat.

Mientras que la parte JSP trabaja obras excelentes, consigo un 404 por parte de servlets Java. Aquí están mis archivos relevantes y estructura de directorios. Puede apuntar a alguien lo que estoy haciendo mal?

(base) $ tree -r
.
└── helloworld
    ├── work
    │   ├── index.html
    │   ├── images
    │   │   └── Pivotal_Logo.png
    │   ├── hello_world_jsp.jsp
    │   └── WEB-INF
    │       ├── web.xml
    │       └── classes
    │           └── examples
    │               └── Hello_World_Java.class
    ├── web
    │   ├── index.html
    │   ├── images
    │   │   └── Pivotal_Logo.png
    │   ├── hello_world_jsp.jsp
    │   └── WEB-INF
    │       └── web.xml
    ├── src
    │   └── examples
    │       └── Hello_World_Java.java
    ├── helloworld.iml
    ├── dist
    │   └── hello_custom_build.war
    └── build.xml

12 directories, 13 files

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">

    <display-name>HelloWorld Application</display-name>
    <description>
        This is a simple web application with a source code organization
        based on the recommendations of the Application Developer's Guide.
    </description>

    <servlet>
        <servlet-name>HelloServlet</servlet-name>
        <servlet-class>examples.Hello_World_Java</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>HelloServlet</servlet-name>
        <url-pattern>/Hello_World_Java</url-pattern>
    </servlet-mapping>

</web-app>

index.html

<html>
<head>
    <title>Sample "Hello, World" Application</title>
</head>
<body bgcolor=white>

<table border="0" cellpadding="10">
    <tr>
        <td>
            <img src="images/Pivotal_Logo.png">
        </td>
        <td>
            <h1>Sample "Hello, World" Application</h1>
        </td>
    </tr>
</table>

<p>This is the home page for the HelloWorld Web application. </p>
<p>To prove that they work, you can execute either of the following links:
<ul>
    <li>To a JSP page: <a href="hello_world_jsp.jsp">Hello JSP Page</a>.
    <li>To a servlet: <a href="/Hello_World_Java">Hello via Java app</a>.
</ul>

</body>
</html>

Hello_World_Java ejemplos del paquete;

java.io.IOException importación; java.io.PrintWriter importación; javax.servlet.ServletException importación; javax.servlet.http.HttpServlet importación; javax.servlet.http.HttpServletRequest importación; javax.servlet.http.HttpServletResponse importación;

public final class Hello_World_Java extends HttpServlet {


    /**
     * Respond to a GET request for the content produced by
     * this servlet.
     *
     * @param request The servlet request we are processing
     * @param response The servlet response we are producing
     *
     * @exception IOException if an input/output error occurs
     * @exception ServletException if a servlet error occurs
     */
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
            throws IOException, ServletException {

        response.setContentType("text/html");
        PrintWriter writer = response.getWriter();
        writer.println("<html>");
        writer.println("<head>");
        writer.println("<title>Sample Application Servlet Page</title>");
        writer.println("</head>");
        writer.println("<body bgcolor=white>");

        writer.println("<table border=\"0\" cellpadding=\"10\">");
        writer.println("<tr>");
        writer.println("<td>");
        writer.println("<img src=\"images/Pivotal_Logo.png\">");
        writer.println("</td>");
        writer.println("<td>");
        writer.println("<h1>Sample Application Servlet</h1>");
        writer.println("</td>");
        writer.println("</tr>");
        writer.println("</table>");

        writer.println("This is the output of a servlet that is part of");
        writer.println("the Hello, World application.");

        writer.println("</body>");
        writer.println("</html>");
    }
}
Andrés:

Por su comentario, parece que faltan el nombre de la aplicación en la url. Debe ser algo como:

localhost: 8080 / [app-name] / Hello_World_Java

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=367596&siteId=1
Recomendado
Clasificación