Can a JavaBean access methods/implicit objects of the JSP page which created it?

Ryan Breidenbach

Yes, they can, but not by virtue of the fact that they are being used in a JSP page. In order for a JavaBean to access the methods/implicit objects of a JSP page, it has to be initialized with a handle or reference to the page itself.

For instance, your JavaBean could have the following code:

private JspPage jspPage;

public JspPage getJspPage()
    return jspPage;

public void setJspPage(JspPage jspPage)
    this.jspPage = jspPage;

Then, from within your JSP page, you could invoke:

<jsp:useBean id="yourBean" class="your.package.YourBean" />
<% yourBean.setJspPage(this); %>

Now, your bean can access the implicit objects and methods of the calling JSP page.