Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What's the best way to handle multiple Java bean instance in Jsp?

 
wei Qiao
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am anewbie for Jsp/Servlet and a have a important question:
Does Jsp expose only one java bean instance to the container?
I am using Struts/Jboss/Tomcat solution.
Suppose I have multiple instances to handle in Jsp even different java beans, how do I implement. I am using session or request to pass those beans to a action servlet to do the process. One of my co-worker use client-side Javascript to hold those values.
What's the best way to do it. Is Jsp designed to handle one bean at a time ?

many thanks!
 
Phil Hanna
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are no restrictions on the number of beans a JSP can use:
<jsp:useBean id="b1" class="com.mycompany.Class1"/>
<jsp:useBean id="b2" class="com.mycompany.Class2"/>
...
<jsp:useBean id="bn" class="com.mycompany.Classn"/>
------------------
Phil Hanna
Author of :
JSP: The Complete Reference
Instant Java Servlets
 
wei Qiao
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, I know that, but my problem is we using the Struts/jboss/tomcat in my project. We use Form beans which handle the Form in JSP and action beans do the dopost/doget kind of thing. It looks like the Struts(ejb container?) will get fields out from Jsp page(which contains a form) and call the appropriate Action bean as well as set the Form bean. In this case, since I only have a field(like textarea) associated with the field of one bean instance(the other instances are stored and active when user select them one by one from a radio button),
How can Struts know which bean instance to be updated?
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Wei,
I am not very sure, if I have understood your requirement.I assume the following:

  1. Strut is the EJBContainer
  2. You have Form Beans and Action Beans defined as Phil has suggested in your JSP

  3. If that is the case, your ActionBean would make an invocation to your EJB Beans in the Strut.The Strut would give the result back to your Action Bean.The instances of the Action Bean would be handled by the JSP Engine, so we need not worry about it.
    Let me know your views on this.
    Regards,

    ------------------
    Sandeep Desai
    vgdesai@bom3.vsnl.net.in

    1. Sun Certified Java Programmer Scored 93 per cent
    2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
    3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
    4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic