Doget called double berth

I use the built-in berth server in a java application. But the doGet () method is called twice. It is also called as a result of this (method.equals (METHOD_GET)) condition in the service method of the httpservlet class.

I tried to execute the query using both chrome and explorer, but I had the same result.

can anyone see the reason for calling dota again ..

public class HelloServlet extends HttpServlet{
  private String greeting="Hello World";
    public HelloServlet(){}
    public HelloServlet(String greeting)
    {
        this.greeting=greeting;
        System.out.println("started the server" + greeting);
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        response.setContentType("text/html");
        response.setStatus(HttpServletResponse.SC_OK);
        response.getWriter().println("<h1>"+greeting+"</h1>");
        response.getWriter().println("session=" + request.getSession(true).getId());
        count = count+1;
        System.out.println(count);
        response.getWriter().println("count=" + count);
        response.flushBuffer();
    }
}

public class OneServletContext{
public static void main(String[] args) throws Exception
{
    Server server = new Server(8080);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);
    System.out.println("about to start the servlets");
    context.addServlet(new ServletHolder(new HelloServlet()),"/*");
   context.addServlet(new ServletHolder(new HelloServlet("Buongiorno Mondo")),"/it/*");
   context.addServlet(new ServletHolder(new HelloServlet("Bonjour le Monde")),"/fr/*");

    server.start();
    System.out.println("started the servlets");
    server.join();
}
}
+5
source share
1 answer

, . , http://foo.com http://foo.com/favicon.ico. , , . . :

System.out.println("request URI=" + request.getRequestURI());
+7

All Articles