Question about Stateful bean

I am facing problem in statefull bean. Actually I am instantiating bean and after setting all properties of bean saving it on session. then I fetch it from session to do further task. because I find this method in many sites and books.  As I use home.create(), can I use home.activate(), to fetch object from container for current session. or any other way to do this.

Ankit

You can try by following code. It is used to create homehandle in MyServlet and out in session. In MyServlet1 it is getting that handle and reconstruct the home and remote interface.

public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String empid=req.getParameter("empid");
String empname=req.getParameter("empname");
HttpSession hs=req.getSession(true);
try{
InitialContext ctx=new InitialContext();
handletestHome hm=(handletestHome)ctx.lookup("ejb/ibm/handletestHome");
HomeHandle Homeh=hm.getHomeHandle();
hs.setAttribute("hndl",Homeh);
}catch(Exception e){
System.out.println(e);
e.printStackTrace(); 
}
System.out.println(" ################### REDIRECTED");
resp.sendRedirect("MyServlet1");


}

}


public class MyServlet1 extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
HttpSession hs=req.getSession(false);
try{
HomeHandle HH=(HomeHandle)hs.getAttribute("hndl");
handletestHome home=(handletestHome)HH.getEJBHome();
handletest RI=home.create("12345","SAMEER KUMAR"); 
}catch(Exception e){
System.out.println(e);
e.printStackTrace(); 
} 
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
}
}
Umapada Manna

Do you have a Java Problem?
Ask It in The Java Forum

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.