"Richard A. Sand" wrote:

>  Hi all, Is there any easy way to get the application or session
> context from within a bean that is invoked from a JSP page?  I know
> that I can make get and set methods in the bean and then have the JSP
> page set them that way, but what I'm trying to do is make session
> beans that don't have to be initialized in every JSP page.  Ideally
> what I'd like is an extension to the JSP engine that always sets a
> session and application variable in a bean if a newly instantiated
> bean. The reason is, in my app I have 4 different beans that can be
> used in a number of combinations amongst 50 or so JSP pages, and I
> don't want to put java code into every one that checks if the bean is
> new and then initializes it.  I thought about extending the JspInit
> method to initialize my beans, but then that means that the JspInit
> method has to be aware of each bean that the Jsp page is going to ask
> for.  I'm into murky waters here with my understanding of JspInit and
> such- can what I want to do be done? BTW I'm using JSP 1.0. Thanks!
> Richard Sand ([EMAIL PROTECTED])
> http://www.vgalleries.com

If your bean needs to know about servlet context or session attributes
directly, you need to pass them (either the other attributes themselves,
or the ServletContext or HttpSession instances) directly as method
arguments to some method of your bean that saves them for later use.
This is a basic Java programming issue, and nothing specific to servlets
and JSP.

On the other hand, the fact that you find this necessary means you
should really spend some time looking at your application architecture.
Beans that need to know they are invoked by servlets are probably not as
well factored (in the object oriented design sense) as they should be.

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to