user3279337
user3279337

Reputation: 451

Servlet abnormal invoking

I have a servlet:

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

I cannot figure out why it prints "1" twice. Who can explain that?

Output:
1
1

Upvotes: 1

Views: 57

Answers (3)

jacquard
jacquard

Reputation: 1307

You can print out

request.getRequestURI() 

to confirm the URLs for the two requests.

Upvotes: 1

Mobi
Mobi

Reputation: 645

It may because of your servlet annotation. @WebServlet ("/*") try with this @WebServlet( displayName="Notification Servlet", urlPatterns = {"/yourservletpath"})

Upvotes: 0

iPouf
iPouf

Reputation: 93

A browser send 2 requests. 1 is your GET request and the 2nd one is an attempt to retrieve the favicon.

Upvotes: 0

Related Questions