Servlet: HTTP Status 404 - Not Found

C.Roy :

My Servlet doesn't work at all. I'm getting HTTPS Status 404- Not Found. Below is the complete code for the same:-

index.jsp

<!DOCTYPE html>
      <html>
          <head>
              <title>Page title</title>
              <meta charset="UTF-8" />
         <meta name="viewport" content="width=device-width, initial-scale=1.0" />
         <link href="CSS/cssSheet.css" rel="stylesheet"  type="text/css" />
     </head>
     <body>

         <nav>
             <a href="ControlleurSimple?action=apropos" target="_self">A propos</a>
         </nav>

         <main>
             <h1>Welcome</h1>
             Text here

         </main>
    </body>
 </html>

web.xml

<servlet>
        <servlet-name>ControllerSimple</servlet-name>
        <servlet-class>WebApplication1.ControllerSimple</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>ControllerSimple</servlet-name>
        <url-pattern>/ControllerSimple</url-pattern>
    </servlet-mapping>

ControllerSimple.java

package WebApplication1;

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


public class ControllerSimple extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            /* TODO output your page here. You may use following sample code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet ControllerSimple</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet ControllerSimple at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        }
    }


    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String action = request.getParameter("action");
String jspPage = "/index.html";
if ((action == null) || (action.length() < 1)) {
 action = "default";
}
if ("apropos".equals(action)) {
 jspPage = "/apropos.jsp";
}
RequestDispatcher rd = request.getRequestDispatcher(jspPage);
rd.forward(request, response);

    }

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

    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}

apropos.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Title</title>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <link href="CSS/cssSheet.css" rel="stylesheet"  type="text/css" />

    </head>
    <body>

        <main>
            Text

        </main>
    </body>
</html>

I'm new to the servlet, so maybe I would have missed something. When I click on the link, I have the "HTTP Status 404 - Not Found " error. I really don't understand what I did wrong.

I'm using NetBeans IDE 8.2 and GlassFish 4.1.1

Karim Baidar :

Just check the code snippet, You have a typo mistake. There, you have to change ControlleurSimple to ControllerSimple.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

HTTP Status 404 - Servlet not found

HTTP Status 404 - Not Found - Servlet and JSP

HTTP 404 not found(Servlet not found)

Java Servlet HTTP Status Code 404

HTTP ERROR 404 accessing "name" Not Found (Servlet)

Maven web project HTTP Status [404] – [Not Found]

Eclipse & Tomcat Error: HTTP Status 404 – Not Found:

HTTP 404 status code (Not Found) shown as 302

HTTP Status 404 – Not Found Spring Boot

HTTP Status 404 – Not Found tomcat spring

HTTP Status [404] ? [Not Found] for /login in spring security

HTTP Status 404 – Not Found on Tomcat server

JSP/JDBC: HTTP Status 404 - Not Found

JBoss error report: HTTP Status 404 - Servlet is not available

Java Servlet, http status 404, The requested resource is not available

HTTP status 404 error running TimeForm servlet project in NetBeans

HTTP Status 404 – Not Found: for controller - no view resolvers found in Idea

Insertion of image in mysql using jsp HTTP Status 404 not found

How to redirect "HTTP Status 404 – Not Found" to an error information page in tomcat?

Spring Mvc get HTTP Status [404] – [Not Found] after the submission

Spring Mvc App get - HTTP Status [404] – [Not Found]

HTTP Status [404] ? [Not Found] (The origin server did not find a current representatio)

HTTP Status 404 Not Found For Jersey REST application with Eclipse and Payara server

Why am I getting HTTP Status 404 - Not Found?

Status: 404-Not found

HTTP Status 404 - /LoginAuth

HTTP Status 404 -

HTTP Status 404 - Why server can't find my servlet I mapped to?

Attempt to POST to a servlet results in HTTP Status 404 - Could not find resource for relative