I have many clients that connect to a webservice. Everytime a client perform an action on the DB I want that all client can see the modify, by an updating of the jsp page that show the content of the DB. How can I do this in ajax?
2 Answers
You can simply use websocket to refresh and renew page. use this link what to use websocket: Jsp+tomcat7.047+html5 simple demo based on websocket

- 107
- 11
It is impossible by simply using ajax because the client (browser) don't know wwhen data is updated, and in client / server model, server can't send request to client to tell him.
Instead you should take a look at websockets. For example here : http://www.java2s.com/Tutorial/Java/0360__JSP/CreatingClientServerApplications.htm
Otherwise, you could simply refresh your web page by sending ajax requests periodically. If you are new to javascript, I recommand using jquery. The way to do it depends on your needs.
If you prefer to reload the whole page, see this answer https://stackoverflow.com/a/5404869/5970908.
To reload a portion of the page, you need to query a template, to get the refreshed html. Then insert it somewhere in the DOM. In this case, refer to the following topic https://stackoverflow.com/a/9436594/5970908

- 682
- 1
- 6
- 21
-
"Otherwise, you could simply refresh your web page by sending ajax requests periodically." How can I do this? – valeriot90 Dec 12 '18 at 13:54