开发者

retrieving attribute in iframe

开发者 https://www.devze.com 2023-03-28 03:07 出处:网络
I have problem in retrieving the request attributes in IFRAME. the following are the snippets, in jsp1.jsp, i have 2 IFRAMES whose src are jsp2.jsp and jsp3.jsp .i would like to retrieve the request a

I have problem in retrieving the request attributes in IFRAME. the following are the snippets, in jsp1.jsp, i have 2 IFRAMES whose src are jsp2.jsp and jsp3.jsp .i would like to retrieve the request attributes in both the pages.Basically the attribute is an object of a class and some values were set for class variables in the jsp1.jsp page.I would like to share that object between these 3 pages. Inside the IFRAME i am getting null value for the attribute..I have tried both session.setAttribute and request.setAttribute

jsp1.jsp

<td>
<%
Search beans=(Search)request.getAttribute("s");
session.setAttribute("s");
%>
<iframe name="frame1" id="frame1" tabIndex="-1" width="100%" 开发者_C百科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
}

Could someone please let me know how to retrieve the set Attribute. And also i can't pass it as an parameter to the jsp2.jsp since it is an object

Thanks Priyam


The HTML <iframe> basically instructs the webbrowser to send a brand new HTTP request on the given src URL and embed its response. It does not run within the request of the parent JSP page in the webserver. So passing objects as a request attribtue ain't going to work. The session will only work if it has already been established before you request the parent JSP page.

I do not understand why you're using an <iframe> this way. It's a very poor approach when the sole purpose is to include page fragments which reside at the same server as the parent page. The <iframe> is only useful whenever you want to embed external content in your webpage.

Replace them by server side includes like <jsp:include> and it'll work the way you initially want.

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

They'll be included within the very same HTTP request and thus have access to its attributes. The benefits are big. Your problem is instantly solved, the SEO will be greatly improved (the <iframe> content is namely not indexed as part of the parent page) and the User Experience also (more predictable and robust website behaviour whenever there are links and forms inside the <iframe>).

0

精彩评论

暂无评论...
验证码 换一张
取 消