• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem using ejb 2.0 stateful session bean

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic