简体   繁体   中英

Error 404 - Java Servlet Doget Controller Method

I cant run a simple hello world message on Servlet. Does anyone know what I am doing wrong? Below is my code: 控制器

错误页面

The server is working normally. Tomcat is version 8.

Any help?

Do you also have deployment descriptor file in your project?

Build new Dynamic Web Project in your IDE and Try this code:

@WebServlet(name = "Hello", urlPatterns = { "/hello" })
public class Hello extends HttpServlet {
protected void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.print("Hello World");
}}

In this case you don't need to write .xml file for this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM