在jsp中的div内包含外部网站 [英] include external website inside div in jsp
问题描述
我想在我的jsp页面的div中包含一个外部网站(例如www.example.com).我不想使用框架,因为这是不可取的.
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.
我尝试在线搜索解决方案,但发现的所有内容包括一个内部网页(例如webpage.jsp)……
I tried searching online for a solution, but all what I found was including an internal webpage (e.g. webpage.jsp)…
非常感谢您的帮助.
推荐答案
首先,如果涉及到划分/包括 local 内容(这是/最常见的),则确实不建议使用框架滥用框架).但是,如果它涉及外部内容,那绝对是可取的.对于本地内容,您应该使用服务器端包含内容,例如<jsp:include>
.
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>
.
关于具体问题,如果外部网站的HTML响应与您自己的JSP页面的HTML响应不冲突(即,它不返回完整的<html>
文档,这将使您的最终HTML响应完全无效,因为重复/嵌套了<html>
元素,但它返回了一些与上下文无关的HTML片段,例如
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" />
但是,如果它返回完整的<html>
文档和/或与上下文相关,则您实际上必须使用<iframe>
或在两者之间引入代理servlet.有关此类servlet的具体启动示例,请查看以下答案:使HttpURLConnection加载带有图像的网页.
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.
这篇关于在jsp中的div内包含外部网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!