Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem using ejb 2.0 stateful session bean  RSS feed

 
ramakrishna kulkarni
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
page1.jsp

<FORM method="post" action="AddItems">
<INPUT type="radio" name="item" value="Thermo Dynamics">Thermo Dynamics
<br />
<INPUT type="radio" name="item" value="Manfacturing Process">Manfacturing Process
<br />
<INPUT type="radio" name="item" value="Machine Theory">Machine Theory
<br />
<INPUT type="hidden" name="nextpage" value="page2.jsp">
<INPUT type="submit" value="Go">


=================================

page2.jsp

<FORM method="post" action="AddItems">
<INPUT type="radio" name="item" value="Thermo Dynamics">Thermo Dynamics
<br />
<INPUT type="radio" name="item" value="Manfacturing Process">Manfacturing Process
<br />
<INPUT type="radio" name="item" value="Machine Theory">Machine Theory
<br />
<INPUT type="hidden" name="nextpage" value="page3.jsp">
<INPUT type="submit" value="Go">

=================================

page3.jsp

<%

out.println(request.getAttribute("itemList"));
%>

=================================
AddItems.java

String item = req.getParameter("item");
String nextpage = req.getParameter("nextpage");

RequestDispatcher rd = req.getRequestDispatcher(nextpage);

Context initialContext = new InitialContext();
Object objref = initialContext.lookup("ejb/ejbs/StatefulDemoHome");
StatefulDemoHome home =
(StatefulDemoHome)PortableRemoteObject.narrow(objref,StatefulDemoHome.class);

StatefulDemo statefulDemo = home.create();
statefulDemo.addItem(item);
List itemList = statefulDemo.getItems();
req.setAttribute("itemList",itemList);

rd.forward(req,res);

=================================

StatefulDemo is a stateful session bean and has an instance variable of type ArrayList
And has below methods

public void addItem(String item){
itemList.add(item);
}

public List getItems(){
return itemList;
}
=================================

I select one radio button in page1.jsp and submit that page and select another radio button in page2.jsp and submit that page Now I am getting only item I have selected in page2.jsp in the page3.jsp

What should we do to get both items which I have selected in page1.jsp and page2.jsp
 
Schandha Ravi
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramakrishna,

Here is my understanding. You can weigh on this.

When you navigated from Page1 to Page2, you are adding the item to the statefull session bean and moving ahead to page 2. Now when you are navigating from page 2 to page 3, are you sure that you are actually calling the same sessionbean. Even though you are using statefull session bean, the next request is a new request altogether and container will assign the new bean. So, by the time you go to the last page, you get results from the last session bean created. Simply to put, I think it is not one single session you are dealing with. I may be completely wrong here. Can you put some debug statements and see if you are actually dealing with only one bean.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!