• Post Reply Bookmark Topic Watch Topic
  • New Topic

stateless bean and parameters  RSS feed

 
Prakash Krishnamurthy
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a stateless session bean and I wish to pass some parameters to the bean instances. I cannot do it through create()/ejbcreate(), since they wont accept parameters. How do I do it then? Through business methods?

Regards,
PK
 
JeanLouis Marechaux
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of *parameter* do you need ? could you explain further ??
 
Prakash Krishnamurthy
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let us just consider a "Hello World" program for its simplicity. Say there is a jsp page that accepts the first name and last name. This then gets passed on to a servlet which calls the create() method on a stateless session bean. Then it calls the business method hello() on the session bean which returns "Hello World, first_name last_name". Now, how do I pass the first name and the last name? A real convenient way to do this would have been to pass the names through the create method. But this is not permitted. So, passing it through the business method(hello(), in this case) is one option.

Is there any better option?

PK
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36443
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prakash,
You should definitely pass the parameters to the business method because they are used in the business method.

Since this is a stateless bean, it shouldn't have instance variables as those could change between, or even during, invocations.
 
Prakash Krishnamurthy
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Since this is a stateless bean, it shouldn't have instance variables as those could change between, or even during, invocations.


What is the solution then?

Regards,
PK
 
Alastair Calderwood
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prakash hello

It might help to say that a SLSB method is similar to a Java static method in that you just provide an input and get an output, but don't ever store class attributes. (The analogy ends here though, as SLSBs have less overhead whereas static methods are not very efficient). It is suitable for simple input-output processing where data doesn't need to be saved, whereas a SFSB method is used where the data might be needed by other methods or classes later, after the method you are calling has returned.

Hope this helps.

Alastair
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!