-1

I have a servlet that just outputs a message to the console. I run the application on Tomcat 9.0.80

@WebServlet("/")
public class HomeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Hello");
    }
}

When I try to go to the address "/" in the browser, the message "Hello" is output to the console 2 times. What could be the problem?

I've tried doing this in different browsers. Only safari works fine. I tried reinstalling the system. It doesn't work!

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Press F12 in webbrowser and hit *Network* tab to learn which requests exactly your webbrowser is firing. Do a `System.out.println(req.getRequestURI())` to learn which URI exactly is being requested. But in the end I think that the URL pattern of `"/"` doesn't exactly do what you expected. It's actually a "catch-all" URL pattern and not a "home page" URL patten. Refer to the abovelinked duplicates for the explanation and the proper URL pattern. – BalusC Sep 01 '23 at 09:19

1 Answers1

0

I think the second request is a Favicon.ico request. Favicon.ico solves by putting the icon path in the head tag.