Tomcat 404 на java сервлет - PullRequest
       9

Tomcat 404 на java сервлет

1 голос
/ 29 марта 2020

Я пытаюсь следовать этому уроку https://tcserver.docs.pivotal.io/3x/docs-tcserver/topics/tutwebapp.html#tutwebapp-ant-buildfile и создать свое первое приложение tomcat.

Хотя часть jsp работает нормально, я получаю 404 на java часть сервлета. Вот мои соответствующие файлы и структура каталогов. Может кто-нибудь указать, что я делаю неправильно?

(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

веб. 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 примеры пакетов;

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;

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>");
    }
}

1 Ответ

1 голос
/ 29 марта 2020

Судя по вашему комментарию, вы пропустили название приложения в URL. Должно быть что-то вроде:

localhost: 8080 / [app-name] / Hello_World_ Java

...