• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stateless bean is maintaining the state

 
Hemasa Rangrej
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,
i have a member variable in stateless bean
i have a method called getTestString() which returns the member variable
private String privateString= new String( "Hello" );
public String getTestString()
{
return privateString;
}
i have a method called changeTestString() which appends "changed" to member variable.
public void changeTestString()
{
privateString= new String( "changed" ) + privateString;
}
my JSP goes like this
<%
Properties prp=new Properties();
prp.put( Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.T3InitialContextFactory");
prp.put(Context.PROVIDER_URL,"t3://machine ip:7001");
InitialContext ctx=new InitialContext(prp);
TestBeanHome home=(TestBeanHome)ctx.lookup("testinghome");
TestBeanRemote beanObj=home.create();
%>
<br><%=beanObj.getTestString()%>
<br><%beanObj.changeTestString();%>
<br><%=beanObj.getTestString()%>
<%beanObj.remove();%>
syntactically everything is fine.
problem is:
when i access the jsp, i get the output as
Hello
changedHello
when i refresh the page i get output as
changedHello
changedchangedHello
this second output is wrong because it is maintaining the previous value of member variable
i will appreciate any solution for this.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The trick here is that the specification does not require the container to "reset" the internal state of stateless session beans--it expects the bean provider to do that. So, what you're seeing is correct behaviour from a spec-compliancy point of view. If you have a stateless session bean, why are you using it as if it was stateful?
 
Hemasa Rangrej
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx Lasse Koskela
i was trying the ejb examples
and i wanted to check the defination "stateless beans does not maintain the state" so i tried this kind of example.
i found some material in http://www.ejbtut.com/StateLess.jsp
by which i think the result what i am getting and what u told is right.
thanx a lot.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!