asynchronous widget JSP foreach (Java EE applicati

2019-07-29 14:34发布

I have the following code in a JSP page:

<c:forEach var="widget" items="${widgets}">
        <p><h2>Widget</h2></p>
        <p>IDType: ${widget.id}</p>
        <p>Name: ${widget.name}</p>  
</c:forEach>

At the moment it is only text that will be displayed, but in the future there will be charts and images as well. I would like to use asynchronous loading, so the page doesn't have to wait on the largest images/charts. On the internet I found tutorials for Java code, but not for JSP pages. What is the best way to implement asynchronous loading in JSP pages?

Thanks!

1条回答
一纸荒年 Trace。
2楼-- · 2019-07-29 15:34

Simply generate these images and charts separately using different servlet:

<c:forEach var="widget" items="${widgets}">
    <p><h2>Widget</h2></p>
    <p>IDType: ${widget.id}</p>
    <p>Name: ${widget.name}</p>  
    <img src="chart-servlet.png?id=${widget.id}"/>
    <img src="image-servlet.png?id=${widget.id}"/>
</c:forEach>

On the server side map some servlets to chart-servlet.png and image-servlet.png. You can then use id parameter to generate appropriate chart or image. From the browser perspective it first renders DOM without images to then ask server for external resources (images).

查看更多
登录 后发表回答