I'm creating a web page using Spring which refreshes the page at regular intervals in order to show up-to-date data. Below is a condensed version of my code which uses Timer for scheduling the refresh after 5 seconds for testing purposes.
@Controller
public class IndexController {
private String id;
private Timer refreshTimer = new Timer();
@GetMapping("/{id}")
public String greeting(@PathVariable String id, Model model) {
this.id = id;
refreshTimer.schedule(new RefreshTask(), 5000L);
return "index";
}
private class RefreshTask extends TimerTask {
@Override
public void run() {
// refresh view
}
}
}
However, about the only information I've found about refreshing views is having a @RequestMapping method return the url prefixed with "redirect:". Is it possible to refresh the view using TimerTask.run() or similar methods without waiting for the view to send a request?