• Post Reply Bookmark Topic Watch Topic
  • New Topic

Retrieving Request Attribute in IFRAME  RSS feed

 
John Vergis
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, I have problem in retrieving the request attribute in IFRAME.
the following are the snippets, in jsp1.jsp, i have an IFRAME whose src is jsp2.jsp, where i would like to retrieve the set request attribute, this value i can retrieve in jsp1.jsp, but inside the IFRAME i am getting null value..

jsp1.jsp
--------

<td>
<%
Collection beans=(Collection)request.getAttribute("CachedBeans");
out.println("Size of cacheBeans is "+beans.size()+);
%>
<iframe name="frame1" id="frame1" tabIndex="-1" width="100%" height="100%" frameborder="0" src="jsp2.jsp"></iframe>
</td>

jsp2.jsp
--------

Collection beans = (Collection)request.getAttribute("CachedBeans");
if (beans != null) {
Iterator beansIterator=beans.iterator();
while (cacheBeanIterator.hasNext())
{
//process the bean
}
}

I am able to get the set attribute in jsp1.jsp and it prints the size properly, but in the iframe where the src is set to jsp2.jsp, if I try to retrieve the attribute's value, then it is returning null, could ne1 please let me know how to retrieve the set request Attribute. And also i can't pass it as an parameter to the jsp2.jsp since it is a Collection object


Thanks
John
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason for the behavior you are seeing is that the requests being processed in the parent page and in the iframe are separate requests, and each will have their own request contexts. So attributes set into one request context will not be visible to the other.

You don't say exactly how the attribute is set in the first place, but in general one thing that the requests will have in common is that they will belong to the same session. So depending upon the specifics of what you are trying to do, it may make sense to place the attribute on the session so that it can be shared across requests.

Be aware that because the session does not go out of scope until it expires, you should be careful to explicitly remove the attribute once it is no longer needed.
 
John Vergis
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The attribute is set in the Action Class --> request.setAttribute("CachedBeans",beans);, where on success it is forwarded to jsp1.jsp, And in jsp1.jsp as i mentioned, I am able to get the set CachedBeans value which is a collection object, I did setting the same request attribute in jsp1.jsp, but even then the value was not visible to jsp2.jsp.

Thanks
John
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but even then the value was not visible to jsp2.jsp.


Correct. See my explanation above.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!