首页 > 解决方案 > 站点被 ping 后如何运行方法?

问题描述

我有一个 servlet 需要在站点被 ping 后运行一个方法。

My servlet:

  @Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

   this.myMethod();
}

它需要myMethod()在站点被 ping 通后运行。如何实施?

标签: javaservlets

解决方案


You said:

after the site has been pinged.

"ping 127.0. 0.1."

Incorrect, your web site is not being pinged. The host computer (OS) is being pinged.

The ping utility tool present in most operating systems makes a brief connection to your host computer, but not to your web server. So no Servlet will be invoked.

Therefore you cannot run code within your Servlet container in response to a ping connection.


推荐阅读