does not process the servlet

I write my first servlet in Java EE, I use tomcat, for some reason my class is not processed, and it always outputs

enter a description of the image here

Here is the code

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

//@WebServlet("/hallo")
public class HalloServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter printWriter = resp.getWriter();
        printWriter.write("Hallo World");
    }
}

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">

<servlet>
    <servlet-name>HalloServlet</servlet-name>
    <servlet-class>HalloServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>HalloServlet</servlet-name>
    <url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>

I'm confused that the search bar says http://localhost:8080/ee_war_exploded/ shouldn't it be http://localhost:8080/hallo ?

Author: Djoni, 2019-11-11

1 answers

Tomcat adds the application context to the url for your servlets. This is done so that multiple applications (war'nicks) can exist on a single application server (Tomcat) without conflicts. This context is by default the name of your application. I.e. the name of the folder that lies in $CATALINA_BASE/webapps. In this case, it is ee_war_exploded. Accordingly, your service will be available at http://localhost:8080/ee_war_exploded/hello

 0
Author: Темка тоже, 2019-11-12 11:35:21