我对Servlets
很新。我无法弄清楚以下代码的行为。
public class HelloServlet extends HttpServlet {
static int counter = 0;
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException {
if (counter == 0) {
httpServletResponse.getWriter().print("Counter = " + counter);
counter++;
} else {
httpServletResponse.getWriter().print("Counter = " + counter);
}
}
}
当我部署并运行它时,结果为" Counter = 1"在浏览器中。为什么跳过" Counter = 0"直接打印" Counter = 1"?