How to use a single JavaBean in many pages accross a JSP frameset
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
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.
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.
精彩评论