HTTP Status 404 – Not Found - The origin server did not find a current representation for the target resource

14 Views Asked by At

** I Am Using TOMCAT - 9 **

I am new to TOMCAT and

Below is my Folder Struc enter image description here

I am trying to call a Servlet from index.html page but it shows 404 error, Could anyone help me out with this.

WEB.xml file

<web-app>
    <servlet>
        <servlet-name>HelloServlet</servlet-name>
        <servlet-class>com.bms.Hello</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>HelloServlet</servlet-name>
        <url-pattern>sample/hello</url-pattern>
    </servlet-mapping>
</web-app>
index.html

<ul>
<li>To a <a href="WebContent/JSP/hello.jsp">JSP page</a>.
<li>To a <a href="hello">servlet</a>.
    <li>To a <a href="WebContent/JSP/CustomerLogin.jsp">Customer Login</a>.
</ul>
Hello.java

package com.bms;

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("/sample/hello")
public final class Hello extends HttpServlet {
    public Hello() {
    }

    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 Bro Servlet Page</title>");
        writer.println("</head>");
        writer.println("<body bgcolor=white>");
        writer.println("<table border=\"0\">");
        writer.println("<tr>");
        writer.println("<td>");
        writer.println("<img src=\"images/tomcat.gif\">");
        writer.println("</td>");
        writer.println("<td>");
        writer.println("<h1>Sample Bro Servlet</h1>");
        writer.println("This is the output of a servlet that is part of");
        writer.println("the Hello, World application.");
        writer.println("</td>");
        writer.println("</tr>");
        writer.println("</table>");
        writer.println("</body>");
        writer.println("</html>");
    }
}

I have tried placing the Servlet file in other places but no result.

0

There are 0 best solutions below