Here ya go:
public class bean1
{
}
public class bean2
{
private HttpSession session = null;
public bean2()
{
}
public init(HttpSession session)
{
this.session = session;
}
public String getBean1SessionName()
{
Bean1 b1 = (Bean1) session.getAttribute("Bean1Name");
if( b1 != null )
return b1.getSomeStringValue();
else
return "";
}
}
<%
b2.init(session);
%>
<%= b2.getBean2SessionName() %>
> -----Original Message-----
> From: A mailing list about Java Server Pages specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of John Thomas
> Sent: Saturday, January 20, 2001 12:31 AM
> To: [EMAIL PROTECTED]
> Subject: Re: how to access the contents of a session object from another
> s ession object directly
>
>
> Hi,
> Can u please show a sample code which would retrieve the b1
> session object, in bean b2 once session has been passed as a parameter
> to an instance variable in b2. Do i have to use the
> session.getAttribute method to retrieve the object or is htere a
> better method.
>
> hanks for the help
> Regards
> John
>
>
>
>
> "Duffey, Kevin" <[EMAIL PROTECTED]>@java.sun.com> on 01/20/2001
> 12:54:15 PM
>
> Please respond to A mailing list about Java Server Pages specification
> and reference <[EMAIL PROTECTED]>
>
> Sent by: A mailing list about Java Server Pages specification and
> reference <[EMAIL PROTECTED]>
>
>
> To: [EMAIL PROTECTED]
> cc:
> Subject: Re: how to access the contents of a session object from
> another s ession object directly
>
>
> I don't believe you can do this unless you pass in the HttpSession to
> the b2
> method. From there you could then gain access to the session within
> that
> bean. You may want to create an instance field in the b2 bean, and in
> the
> page call b2.init(session); then any call throughout the bean will
> have
> access to the session without it having to be passed in to each bean
> method.
> In your init method you would assign the passed in session to the
> instance
> reference for it.
>
>
> -----Original Message-----
> From: John Thomas
> To: [EMAIL PROTECTED]
> Sent: 1/19/2001 10:20 PM
> Subject: how to access the contents of a session object from another
> session
> object directly
>
> Hi all,
> I face a problem , How can i access the contents of session
> object from another session object belonging to the same session
> directly ie
> i have a session bean
> Bean1 b1;
> methods: String getData();
>
> and another session bean
> Bean2 b2
> method : setObject(String value)
>
> boths beans are inialized as session objects by using the <usebean>
> tag, The question is how will i call b1.getData() in b2's setObject()
> directly , where b1 and b2 belong to the same session.
>
> pls note: I don't want to pass b1 as parameter to b2 from jsp page,
> because i want the container to automatically set the value of
> setObject() using the <setProperty> tag.
>
> Regards,
> John
>
> ========================================================================
>
> ===
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
> ==================================================================
> =========
>
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
> ==================================================================
> =========
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set
> JSP-INTEREST DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets