views:

97

answers:

2

Hi

I have a bean declared on a page that holds a frameset

<jsp:useBean id="pos" class="MyBeanscope="page">
<jsp:setProperty name="a" property="a"/>
</jsp:useBean>

[some initialisation of MyBean]

<frameset ... >
    <frame src="/myframe1.jsp"...>
    <frame src="/myframe2.jsp"...>
</frameset>

My question is, how do I access MyBean in the jsps that belong in the frameset? If I declare them again within each frame jsp, I think I'll end up with three of them.

Thanks for any help

Ryan

+1  A: 

Like the IMG tag, the FRAME tags each become another browser request to the server for the referenced JSPs. So that's 3 separate requests. Since they are separate requests, each of the JSPs should declare its own bean.

If the bean is expensive to create, you could scope it to the session, ready for the "framed" JSPs.

marklai
Thanks for your response. However, my aim is to use the *same* bean in all pages. Set-up isn't expensive, but I want to persists some state between the pages. Thanks - Ryan
Ryan
You can't. You'll have to use the server as the link between the 3 pages
Valentin Rocher
+2  A: 

Do not use HTML frames to include partial/template content. This is 1) not SEO friendly, 2) not user friendly, 3) not developer friendly --as you found out, 4) very 90's HTML style (where did you learn about frames again? throw that old fashioned book/tutorial away and go get a modern one).

Rather do it entirely the server side. Use jsp:include to include partial/template content.

<jsp:useBean id="pos" class="MyBeanscope="page">
    <jsp:setProperty name="a" property="a"/>
</jsp:useBean>

[some initialisation of MyBean]

<jsp:include page="/myframe1.jsp"...>
<jsp:include page="/myframe2.jsp"...>

Of course you can place them in some div's and use CSS to position/style them.

BalusC
Thanks for the advice. I will take it. However, how do I reference the 'pos' bean in myframe1.jsp and myframe2.jsp?! Thank you - Ryan
Ryan