You cannot directly execute the command on the client directly from the servlet. Note that the http protocol relies on client requests and server responses.
So, if a request is not received from the client, then nothing can be sent from the server (simply because the server does not have a response request)
I know that you saw this functionality, and yes, it can be done. But not like that. Ajax is your best bet here ... (sending requests at regular intervals and receiving a response from the server, etc.)
source share