I would like to include an external website (e.g. www.example.com) in a div in my jsp page. I don’t want to use frames since it’s not advisable.
I tried searching online for a solution, but all what I found was including an internal webpage (e.g. webpage.jsp)…
I’ll really appreciate your help.
First of all, using frames is indeed not advisable if it concerns dividing/including local content (which is/was the most common abuse of frames). But it is definitely advisable if it concerns external content. For local content you should rather be using server-side includes such as <jsp:include>
.
As to the concrete question, if the HTML response of the external website does not collide with the HTML response of your own JSP page (i.e. it does not return a complete <html>
document which would make your final HTML response completely invalid because of duplicate/nested <html>
elements, but it returns some context-independent HTML fragment, e.g. <span>blah</span>
), then you can use JSTL <c:import>
for this.
<c:import url="http://external.com/some/fragment.html" />
But if it returns a complete <html>
document and/or is context-dependent, then you really have to use <iframe>
or to bring a proxy servlet in between. For a concrete kickoff example of such a servlet, check this answer: Make HttpURLConnection load web pages with images.
You're going to face several issues if you want to include an external page in a div
tag only, to name a few:
There are different options to handle requirements like this:
To conclude: there is no easy way of providing an external page in a div
only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With