0

I'm trying some little things on JSP and Servlets for a further project. But I'm now blocked by an idea, but I didn't found a perfect solution to make it works.

The idea is that in a JSP page I've a POST form for my Servlet, to search in some documents. So that the Servlet will create a thread to search in the requested document. But what happens if I want to see the evolution of the search (number of folders explored / total folders for example) meanwhile I continue the navigation on the app, so not on the same page ? I imagined a tooltip permanent on the UI, but i didn't found an exact solution to make it possible.

The solution I saw in some post is to use Ajax for asynchronous requests, but I would do the following :

  • on the thread (model part) : search, and sometime perform a POST on the JSP page with the evolution of search as content of the POST
  • on each JSP page : have something like a "wait for receive" in jQuery, and update the text each time I receive something.

like : Form search POST => Servlet : creates a thread, return on the page (no redirect ? ) Thread => POST on JSP page caught by a JS function => update text

But on some posts I always saw the revert function : jQuery/ajax post on something, and use data after...

Can someone give me the right way to do this ?

Many thanks !

Aeldred
  • 314
  • 2
  • 15
  • 2
    Here's a new search keyword: Push. – BalusC Jun 28 '16 at 12:41
  • Many thanks, it's really what i want ! I was wondered that nothing was present about this on my newbie tutorial ! Thanks for the quick answer !! But just one last question, can i use it for multiple page ? For example i'll give a writer from the context to the thread, and he'll send events, but is the event present on the associated page or to all active pages, if I subscribe to the event on each page ? – Aeldred Jun 28 '16 at 12:45
  • 2
    In case you're using websocket based push, it's by default sent to all pages. Here's a related question: http://stackoverflow.com/q/25947790 (albeit JSF targeted, pretty much all of code in the top answer is applicable on plain JSP/Servlet too, you only have to replace JSF `` snippet by plain HTML/JS code for JSP but that should speak for itself). – BalusC Jun 28 '16 at 12:58
  • Thanks, perfect for my problem :) ! – Aeldred Jun 28 '16 at 13:04

0 Answers0