How do i pass session from a JSP page to a Stateful Session Bean

Discussions

General J2EE: How do i pass session from a JSP page to a Stateful Session Bean

  1. Hi All
    I have the jsp container on machine A and the EJB container on machine B.

    I have to pass the session from the JSP conatiner to the EJB container.

    Can anybody point me in the right direction.

    Any help would be much appreciated.

    Regards
  2. Hi AllI have the jsp container on machine A and the EJB container on machine B.I have to pass the session from the JSP conatiner to the EJB container.Can anybody point me in the right direction.Any help would be much appreciated.Regards
    Hi,
    You want to pass session so I think you want to pass some information from JSP to EJB via Session. Instead of using HttpSession I can think of following ways

    1. You can use a Stateful session bean to store these required values which you want to pass from JSP to EJB. From JSP put the required values in SFSB and on EJB side retrieve the same which is similar to using session.
    2. Other way which I think is more appropriate . If you want to pass some Value object to EJB from JSP then why dont you make that Value Object serializable and pass the EJB method as a part of Method Parameters.
    Please let me know how you have solved the problem
    Thanks
    Amit
  3. Yes I agree with amit. The second method he suggested is much more preferable.
    And the entire HTTPSession is probably not required by the bean anyways, right?
    so then why pass it?

    Cheers
    Ajay
  4. Collect the values into a ValueObject and pass to EJB layer, would be a much suitable way of doing.

    Also, I think one cannot use 'HTTPSession' interface as an argument to a remote call because it's neither a remote object nor serializable.

    -arun
  5. EJB is a server side component that can be accessed by different kinds of client components. By passing HttpSession to EJB, you are restricting the accessibility to web only. As Amit pointed out, by using ValueObject pattern, you can have a clear separation of client and ejb.

    Thanks,
    Senthil.
  6. I just want to say that I agree. Passing the HttpSession as an argument to an EJB seems to be a very good example of an anti-pattern.

    /Tomas