Results 1 to 1 of 1
  1. #1
    iwanabeguru is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default Learning Stateful session beans

    Hi

    I am learning stateful session beans, and I need some help and/or explanation.

    I created a very simple stateful bean.

    Java Code:
    public @Stateful class AdderBean implements Adder {
    
    	private int data=0;
    	
    	public int getData(){
    		return data;
    	}
    	
    	public void addData(int d){
    		data = data+d;
    	}
    
    }
    I created a client servlet which reads an integer parameter from a textbox field, call the addData method of the bean and print the incremented value.

    I have some problems with this little test application. If i get the bean inside the doGet method its behave like a statless bean. It only contains the last inserted value. However if i get the bean in the constructor of the servlet it works like a singleton bean and if i test it in two different browser which maintains two different sessions I can modify only one value and it's shared between two browsers.

    I want to increment the value in the bean through more then one call like it is a very simplified shoping cart bean.

    How can i use this bean?
    Should I have to put the bean reference into the Session object and get it for every call?

    May i misunderstood the concept of the stateful session beans, I think i don not have to maintain session manually when I use enterprise beans.

    Please, provide me a proper method or explanation.
    Thank you for your help.

    iwanabeguru
    Last edited by iwanabeguru; 09-07-2011 at 12:01 PM.

Similar Threads

  1. stateful session bean pool size
    By javakt in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 07-08-2011, 02:08 PM
  2. Stateful Session Bean
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-29-2007, 12:39 PM
  3. Calling a Stateful Session bean in NetBeans
    By JavaForums in forum NetBeans
    Replies: 0
    Last Post: 07-31-2007, 09:21 AM
  4. Introduction to Stateful Session Bean In NetBeans
    By JavaForums in forum NetBeans
    Replies: 0
    Last Post: 07-31-2007, 09:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •