Session beans are the part of Enterprise Java Beans (EJB) which are based on RMI as basic foundation technology. Good Introduction to Enrerprise Java Beans its types and application is been provided by Oracle Inc on its site at J2EE Tutorial (PDF)
A stateless session bean does not maintain a conversational state with the client. When a client invokes the methods of a stateless bean like Remote Method Invocation , the bean’s instance variables may contain a state specific to that client but only for the duration of the invocation. When the method is finished, the client-specific state should not be retained.
Most Often Stateless Session beans are more scalable due to their stateless nature.It is to be noted that it is developers responsibility that he/she does not include any code which may turn out to be a non-transient data for clients request for invocation of session beans business method.
When Creating stateless session beans in NetBeans we need to follow the following steps in general.
As like RMI where every client has a copy of interface containing remote method's declaration , Session Bean's Remote interface is distributed in form of Java Class Library , a .file jar. So before we start creating session bean its good we create a blank Java Class Library Project.
We will be creating a Session Bean with business method "int getSquare(int var)" which would return us square value of argument passed. Finally we will create a java servlet to access Session Bean's business method as a client.
Step 1: Create a blank Java Class Library Project. with a proper name and remember the name of the the project created you need select this project while creating Remote interface for Session Bean in Step 2
Step 2: Create an Enterprise application with EJB Module and Web Project. Ensure that you are selecting GlassFish as a Server ,since Apache Tomcat does not come with EJB Container.
Add a new Session Bean to the EJB module , the type of Session bean should be Stateless and also create Remote and Local Interfaces for the created Bean
While creating Remote interface you need to select the Java Class Library Project which you have created in Step 1 to hold Remote interface which would be containing Business method's declaration.
Step 4: Create a Servlet in Web Project and call EJB's Business method
Step 5: Deploy the Enterprise Project and call servlet in browser by using its context path.
Your Servlet's output should look somewhat like below screen
Happy Coding !!! :)