How to import content from an external url to jsp

290 Flares Twitter 0 Facebook 0 Google+ 290 LinkedIn 0 290 Flares ×

In this post i will explain how to import content from an external url jsp. This is a much needed functionality if your page is displaying content from other websites. For instance weather data.

Often we use <%@ include file=”header.html” %> and

to include content from other pages into our jsp. But both of these can only include files from the same web-app. We want to know how to dynamically include content from an external website into our jsp. Before we look at how to achieve that, let us analyze the include directive and jsp:include action.

is static. It adds content from the file attribute in the tag during the translation time. Hence it cannot respond to dynamic events.

is dynamic and includes content from the page attribute at request time. As mentioned earlier, none of these work in the case of an external URL.

To import content from an external URL to a JSP, JSTL provides tag.

For instance

will add the content from the url specified to JSP at the request time.