简体   繁体   中英

how to let know the client what's going on while the servlet is processing the request?

My web application contains JS/jquery as the front end and servlets as the backend. I'm making a request to a servlet which will do whole lot of things in one single call (for example it might call a shell script which will run several python scripts).

I guess my question is, is there a way to notify the client before the servlet's doGet() method returns?

There is a nice mechanism of WebSocket for server to client notifications pushing. You can create Ws end point and then subscribe on it in your client code and notify a clients about progress of operation of your servlet.

I would encourage you to look into ajax post request. There is a nice feature called beforeSend which can allows you to notify a user of 'loading,processing,fetching, executing' and so on. For example:

  $.ajax({
   beforeSend: function(){
     // Handle the beforeSend event
   },
   complete: function(){
     // Handle the complete event
   }
   // ......
 });

For more details on how to handles events with ajax calls refers to the document here http://api.jquery.com/Ajax_Events/ and http://api.jquery.com/jquery.ajax/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM