How do I access JavaBean instanciated in JSP from another Class

Discussions

Web tier: servlets, JSP, Web frameworks: How do I access JavaBean instanciated in JSP from another Class

  1. How do I access a JavaBean that already has been instanciated (with scope session) in an JSP page? I know how to do this from a JSP but how do I do this from another Class or Bean within the web application?

    Thanks in advance for any suggestions,
    El
  2. If you have a reference to the HttpSession called "session" in your class, you can simply call

    [Bean-Type] bean = ([Bean-Type]) session.getAttribute("[Bean-ID]");

    Cheers,

    René