doGet在初始化期间多次调用

时间:2018-01-31 08:31:00

标签: java servlets

我注意到当我的Java servlet启动时,doGet方法被调用3次。之后,如果我刷新使用该servlet的网页,它只会被调用一次。我的servlet正在Google App Engine上运行,所以也许这与它有关。或者这对于任何servlet都是正常的吗?这是servlet代码:

package com.example.demos;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 */
@SuppressWarnings("serial")
public class HelloWorldServlet extends HttpServlet {

    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        PrintWriter out = resp.getWriter();
        out.println("Hello, world");
    }

    public void init() throws ServletException {
        System.out.println("Servlet: init()");
    }

    public void destroy() {
        System.out.println("Servlet: destroy()");
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.service(req, resp);
    }

    protected void processRequest(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("Servlet: processRequest()");
    }
}

0 个答案:

没有答案