【问题标题】:retrieving attribute in iframe检索 iframe 中的属性
【发布时间】:2011-08-16 01:49:23
【问题描述】:

我在 IFRAME 中检索请求属性时遇到问题。 以下是sn-ps,在jsp1.jsp中,我有2个IFRAMES,其src是jsp2.jsp和jsp3.jsp。我想检索两个页面中的请求属性。基本上该属性是一个类的对象并且在 jsp1.jsp 页面中为类变量设置了一些值。我想在这 3 个页面之间共享该对象。在 IFRAME 中,我得到了属性的空值。我尝试了 session.setAttribute 和 request.setAttribute

jsp1.jsp

<td>
<%
Search beans=(Search)request.getAttribute("s");
session.setAttribute("s");
%>
<iframe name="frame1" id="frame1" tabIndex="-1" width="100%" height="100%"   
frameborder="0" src="jsp2.jsp"></iframe>
<iframe name="frame2" id="frame2" tabIndex="-1" width="100%" height="100%" 
frameborder="0" src="jsp3.jsp"></iframe>
</td>

jsp2.jsp

Search beans = (Search)session.getAttribute("s");
if (beans != null) {
//process the bean
}

有人可以告诉我如何检索设置的属性。而且我不能将它作为参数传递给 jsp2.jsp,因为它是一个对象

谢谢 普里亚姆

【问题讨论】:

    标签: jsp iframe request session-variables


    【解决方案1】:

    HTML &lt;iframe&gt; 基本上指示网络浏览器在给定的src URL 上发送全新 HTTP 请求并嵌入其响应。它不在网络服务器中父 JSP 页面的请求中运行。因此,将对象作为请求属性传递是行不通的。只有在您请求父 JSP 页面之前已经建立了会话。

    我不明白你为什么这样使用&lt;iframe&gt;。当唯一的目的是包含与父页面位于同一服务器上的页面片段时,这是一种非常糟糕的方法。 &lt;iframe&gt; 仅在您想在网页中嵌入外部内容时才有用。

    将它们替换为服务器端包括 &lt;jsp:include&gt; 之类的,它会按照您最初想要的方式工作。

    <jsp:include page="jsp2.jsp" />
    <jsp:include page="jsp3.jsp" />
    

    它们将包含在同一个 HTTP 请求中,因此可以访问其属性。好处是很大的。您的问题会立即得到解决,搜索引擎优化将得到极大改善(&lt;iframe&gt; 内容不会作为父页面的一部分编入索引)和用户体验(只要@ 内有链接和表单,网站行为就会更加可预测和健壮) 987654328@)。

    【讨论】:

      猜你喜欢
      • 2021-10-05
      • 2011-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-13
      • 2018-02-26
      • 2011-01-18
      • 1970-01-01
      相关资源
      最近更新 更多