I have been trying to create a servlet in intellij by following this tutorial: https://medium.com/@backslash112/create-maven-project-with-servlet-in-intellij-idea-2018-be0d673bd9af.
Here is the code I have added so far to the servlet class:
package com.demo;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet("/DemoServlet")
public class DemoServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<h3>Hello World!</h3>");
}
}
I also set the run configuration to use Tomcat 9:

When I run the project I can view "Hello World!" on both http://localhost:8080 and http://localhost:8080/DemoServlet.

However, I thought that you should only be able to view "Hello World!" at http://localhost:8080/DemoServlet and not at http://localhost:8080. I would like to know if this is the expected behavior for the program, or did I make a mistake in my configuration of the Servlet?