2 Replies Latest reply on May 22, 2002 11:59 AM by Scott

    retrieving stateful session bean reference in a JSP

    Scott Newbie

      Ello

      I'm trying to access a stateful session EJB accross multiple JSPees. I searched this forum and found a post that said to use the HttpSession interface to store and retrieve a reference to the bean. Duh. The obvious solution. Except they didn't post an example. I think i figured it out, but I'm having trouble getting it to compile (it being the JSP that is retrieving the already-instantiated session bean). Here is the error and line that is causing it:

      Can't make static reference to method java.lang.Object getAttribute(java.lang.String) in interface javax.servlet.http.HttpSession.

      theManager = (manager) HttpSession.getAttribute(attributeName);


      The carrot would be under the opening parens after getAttribute if i wasn't too lazy to put in all the nbsp;s

      I never took any java classes or anything so i don't know all of its crazy rules. i could be making a really simple type-casting error here, i dunno. I thought maybe you have to narrow the object refference but i tried that and it makes no difference to the compiler. The error occurs before it even gets to that step.

        • 1. Re: retrieving stateful session bean reference in a JSP
          Julian Gosnell Expert

          The compiler message gives you everything that you need.

          Find the Java API documentation and look up the API for HttpSession.

          Look around the web for a simple example program that uses HttpSessions.

          If you don't understand the difference between calling a static method and invoking an instance method - get a good book on Java.

          I wish I could help more - but no-one's paying me and there are only so many hours in a day.

          The J2EE in your problem is incidental - you can't call an instance method without an instance.

          Good luck,


          Jules

          • 2. Re: retrieving stateful session bean reference in a JSP
            Scott Newbie

            See, i knew i was making some stupid simple mistake. Stupid me for not seeing it. Heh. Thanks for the help. Oh, and you're right about the java book. I need one _bad!_ I just don't want to pay for it myself, so i'm sitting here waiting for the PO to go through, and letting the compiler teach me in the mean time :)

            Scott