Reputation: 13
How can I refresh a jsp on any change automatically? Is there any way to do it?
In my application I am using JSP to design the header. Now as per requirement I have to make a change in the jsp which is only reflecting when Iam manually refreshing the page.
I want this to be done automatically.
Upvotes: 0
Views: 1972
Reputation: 773
Whatever you're trying to achieve specifically here, you will have to use Javascript in your .jsp page.
If by 'refreshing', you mean literally refreshing the page as if the user clicked the browser's refresh button, then you can use this Javascript code.
location.reload();
What you'll need to do is capture events, in your page, that should cause the page to reload, and then execute the Javascript command above when they occur.
This being said, san krish (above answer, at the moment I'm writing this) suggested AJAX. It is very likely that AJAX is actually the solution you're looking for -- what AJAX means is that you'll use Javascript to only refresh a specific part of the page, instead of reloading the entire page. In a nutshell, AJAX means using Javascript to make requests and retrieve the responses without 'leaving' the page. It's a bit complex to explain shortly, especially given that we are not sure what you are trying to build at the moment, so I will leave it at that.
Upvotes: 0
Reputation: 8217
I have to make a change in the jsp which is only reflecting when Iam manually refreshing the page
Because once you run the jsp file , it renders the html
content to the browser and it doesnt maintain any active connection with the browser unless you are creating a new request.
How can I refresh a jsp on any change automatically? Is there any way to do it?
You can use Ajax as it is meant for this purpose.
Poll the server for regular intervals using the window.setInterval method and update the contents.
Hope this helps !!
Upvotes: 1