1 Reply Latest reply on Apr 7, 2006 1:28 PM by Vijay G

    EJB3.0 OBJECT cannot be acquired in JSP.

    yuka shimizu Newbie

      I am acquiring data from db by calling the SessionBean from the Servlet, and using EntityManager.
      It is not possible to achieve it well though it wants to return Servlet the data of
      the EntityBean type acquired in the SessionBean, and to pass it to JSP.
      It is displayed in the log of jboss, "INFO [STDOUT] null".
      The character of String Type can be normally passed.
      It was similar though not only EntityBean but also the DTO object was executed making it.

      Am I doing something mistake?
      could anyone have advice for me?


       <head><title>EJB Test</title></head>
       <BODY bgcolor="#ffffff">
       Value v = new Value();
       v = (Value)request.getAttribute("__value");
       ListIterator userlist = (ListIterator)v.getAttribute("userlist");
       <table width="400" border="0" cellpadding="0" cellspacing="0">
       <td valign="top">
       <div align="center">
       <table width="400" border="1" cellspacing="1" width="100%" cellpadding="5" height="62">
       <td align="right" width="100" height="30">ID</td>
       <td height="30">passwd</td>
       <td height="30">name</td>
       UserBean user = new UserBean();
       user = (UserBean)userlist.next();
       <td align="right" height="30"><%=user.getUserId()%></td>
       <td height="30"><%=user.getPasswd()%></td>
       <td height="30"><%=user.getName()%></td>

      View Controler Servlet Class
      public class MHServlet extends HttpServlet {
       public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
       String event = "";
       event = new String(req.getParameter("__magazine").getBytes("8859_1"), "EUC-JP");
       Hashtable param = new Hashtable();
       for (Enumeration e = req.getParameterNames(); e.hasMoreElements();) {
       String key = (String)e.nextElement();
       param.put(key, new String(req.getParameter(key).getBytes("8859_1"), "EUC-JP"));
       Value value = null;
       Context context = new InitialContext();
       MH006_001 c = (MH006_001)context.lookup(MH006_001.class.getName());
       value = c.doBiz(param); }
       forward(value, req, res);
       }catch(Exception e){
       private void forward(Value value, HttpServletRequest req, HttpServletResponse res){
       req.setAttribute("__value", value);
       RequestDispatcher rd = getServletContext().getRequestDispatcher(value.getForwardPage());
       rd.forward(req, res);
       }catch(ServletException e){
       puterror(e.getMessage(), res);
       }catch(IOException e){
       puterror(e.getMessage(), res);

      SessionBean Class
      public class MH006_001Bean implements MH006_001, Serializable{
       private String searchId;
       protected EntityManager em;
       public Value doBiz(Hashtable param){
       String page = "/jsp/MH007.jsp";
       int count = 0;
       Value value = new Value();
       searchId = (String)param.get("searchId");
       Query query = em.createQuery("select OBJECT(o) from UserBean o where o.userId like :userId");
       query.setParameter("userId", "%"+ searchId + "%");
       List userlist = query.getResultList();
       count = userlist.size();
       LinkedList ret = new LinkedList();
       for(int i=0; i<count; i++){
       UserBean user = (UserBean)userlist.get(i);
       value.setAttribute("userlist", ret.listIterator(0));
       }catch(Exception ex){
       System.out.println("***** MH006_001Bean.doBiz catch ex = " + ex);
       return value;

      Class returned to servlet(It is in the same package as bean.)
      public class Value implements Serializable{
       private String nextPage = null;
       private Hashtable value = null;
       public Value(){
       value = new Hashtable();
       public void setForwardPage(String page){
       nextPage = page;
       public String getForwardPage(){
       return nextPage;
       public void setAttribute(Object key, Object data){
       value.put(key, data);
       public Object getAttribute(Object key){
       return value.get(key);