Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

include external website inside div in jsp

Tags:

jsp

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.

like image 858
DalNM Avatar asked Aug 08 '11 10:08

DalNM


2 Answers

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.

like image 144
BalusC Avatar answered Sep 25 '22 18:09

BalusC


You're going to face several issues if you want to include an external page in a div tag only, to name a few:

  1. handling links inside the external website
  2. cookie management
  3. resource management (images, css, javascript)

There are different options to handle requirements like this:

  1. iFrame; it's not nice but why isn't it advisable?
  2. server-side reverse proxy; may become complex as you have to filter external links (see #3)
  3. simple frame (somehow outdated)
  4. well-defined interface provided by the external system (e.g. some RESTful stuff)

To conclude: there is no easy way of providing an external page in a div only.

like image 24
home Avatar answered Sep 25 '22 18:09

home