Java servlet and JSP : run process in background and update jsp after

Viewed 33

I am developing a java web application with servlets and JSP. When we arrive on the main page a heavy request is made to the database to retrieve and display information. This request is long so I would like to know if it was possible to display the page and then make this request in the background and update the page once the request is answered.

Thanks for your help

1 Answers

There are a way i use when my DB queries are big enough to make client-side wait some seconds.

Therefore i recomend you to optimize your query and limit it to a certain number of records and set a pagination on your client side.

So, when i know my query is going to last a while, i just put the db request on a secondary jsp. In the main jsp i show to the user a spinner o something and i make the call(to the secondary jsp) with ajax. With this, the first client side request is live and when the DB call ends, y replace the spinner with the content o got with the secondary jsp.

But as i said before, don't make the user wait more than 5 - 6 seconds.

Related