Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC reload parts of the page

My current MVC application in Spring is a classical one - controller returns view name to render, then *.jsp file is rendered to the browser. Simple and bullet-proof :)

What I want to do now is to update parts of the page using AJAX.

Part of the page should be handled by method in controller, something like "taskList" would render readty-to-include html with list of tasks.

It's all fine and dandy with ajax itself - I just create holding div in page and populate it with html from that request.

Now the question: Is there a way to include that html in page on server side? Something like (warning: pseudocode :))

<div id="taskListHolder">
    <someSpringtag:include 'taskList' />
</div>

Basically I want to include html from one controller response in another. So in case of first page load no AJAX is necessary and it would also work when JS is disabled.

What are the best practices to do such a thing?

Thanks! Leonti

like image 568
Leonti Avatar asked Dec 04 '25 16:12

Leonti


1 Answers

Try using Core JSTL tag library:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<body>
<div id="taskListHolder">
<c:import url="http://your-link-to-ajax-list"/>
</div>
</body>
</html>
like image 135
igo Avatar answered Dec 07 '25 15:12

igo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!