[servlet] A rookie, learning servlet according to the tutorial, keeps displaying 404. I don't know why.

URL: tutorials I refer to

I typed the code according to the tutorial I referenced.

first, the java code is:

//java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;


//HttpServlet 
public class HelloWorld extends HttpServlet {
    private String message;
    public void init() throws ServletException
    {
        //
        message = "Hello World";
    }

    public void doGet(HttpServletRequest request,HttpServletRequest response) throws ServletException,IOException {

        //
        response.setContentType("text/html");

        //
        PrintWriter out = response.getWriter();
        out.println("<h1>" + message + "</h1>");
    }

    public void destroy()
    {
        //
    }
}
After compiling this code successfully, I followed the tutorial and put the class file into < Tomcat-installation-directory > / webapps/ROOT//WEB-INF/classes (there is no classes folder under the WEB-INF file, and then I created a new one myself)

clipboard.png

xml

clipboard.png

clipboard.png


Tomcatbinstartup.up
:http://localhost:8080/HelloWorld
:

clipboard.png
tomcat

clipboard.png

so I"d like to ask what the problem is.

Jul.04,2022

404 means that the specified path cannot be found. You can check whether the path of your servlet is written correctly, mainly by checking the path in the xml file. For example, whether the path under the < servlet-class > tag can be located to your class file


your controller is not mapped to helloworld,mapping. Write a


HelloWorld class source code and add a package name. Add the package name and remember to change the web.xml file.


I see. The problem is compilation.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b6b6-2c286.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b6b6-2c286.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?