Using a Statefull Session Bean with RMI on Multiple JSP pages

Heya all,
i have a JBoss server running with a statefull bean on it. I want to use it on my JSP pages. But every time I start my JSP-page a NEW INSTANTION of the bean is created! For each user using my page, I want ONE bean.
Is there anyway to do this? ANything with the sessioncontext?
I can do it with local beans, using the simple tags in the JSP-page, but they do not work for Remote Beans.
(I use JNDI)

hi,
statefull session beans are client session specific. the instance will exists if client session exits.
now since u are loading the jsp page again in the other browser, a new instance will be associated with the current session.
hope it will work.
sameer

Similar Messages

  • Newbie: How do i use a stateless session bean in a backing bean?

    I have a stateless session bean with a function 'getVoterList()'; how do i instantiate the bean and use it in from my managed bean?
    I dont want to use seam; coz the stateless serrion bean/EJB is written by another developer and we cant updat eit now to use seam..
    any tutorials? walk thrus or sample code?
    thanks
    illi

    I used a different method...
    I used servicegen with only a.jar to create the ear.
    I touch-ed my own application.xml to make it newer than the one already in the
    newly created ear.
    I used the ant <ear> task to add b.jar, c.jar, and application.xml to the ear.
    Worked like a charm.
    Mike
    Bruce Stephens <[email protected]> wrote:
    Hello,
    See if Neal's answer here helps solve your problem using servicegen's
    service element "IncludeEJBs" attribute:
    http://newsgroups.bea.com/cgi-bin/dnewsweb?cmd=article&group=weblogic.developer.interest.webservices&item=2932&utag=
    HTHs,
    Bruce
    kk wrote:
    This is my situation.
    I have an .ear file and in that i have several other .jar files whichare
    inter-dependant, lets say
    A.jar
    B.jar
    C.jar files
    and i want to expose only A.jar as
    webservice, how can i do that ?
    Does WLS8.1 provided any way how to do that?
    I Appreciate any suggestions and advices.
    Thanks
    kk

  • Stateful Session Bean with BMT: JDBCpmf or EEpmf?

    Quote:
    For the record: when using BMT as David described, you should use a JDBCPersistenceManagerFactory
    instead of an EEPersistenceManagerFactory. EEPersistenceManagerFactory is only appropriate when
    transaction synchronization is desired.
    -Patrick
    Hi Patrick,
    I wanted to follow up on this. In the case of Kodo, the JDBCpmf does not turn on the
    UserTransaction in a managed environment, while the EEpmf does. My question: isn't is necessary to
    turn on the UserTransaction in a stateful session bean with BMT? If this doesn't happen, isn't
    there a danger, if the bean allows transactions to span business method invocations, that the
    container will passivate the bean while a transaction is active? Since the PM can't be saved during
    passivation, the tx would be interrupted by passivation -- something that would not happen if the
    container were aware that a tx was active.
    David Ezzio

    David,
    My interpretation of your initial post was that you were using fully
    unmanaged transactions in your bean. That is, that you were not using the
    UserTransaction, but were just using the javax.jdo.Transaction for
    transactional data store access.
    In the situation I just described, using the EEPMF would result in changes
    to the UserTransaction. If your goal was to manage the UserTransaction in
    the bean, then yes, you'd still want to use the EEPMF.
    -Patrick
    On 7/25/02 7:17 PM, "David Ezzio" <[email protected]> wrote:
    Quote:
    For the record: when using BMT as David described, you should use a
    JDBCPersistenceManagerFactory
    instead of an EEPersistenceManagerFactory. EEPersistenceManagerFactory is only
    appropriate when
    transaction synchronization is desired.
    -Patrick
    Hi Patrick,
    I wanted to follow up on this. In the case of Kodo, the JDBCpmf does not turn
    on the
    UserTransaction in a managed environment, while the EEpmf does. My question:
    isn't is necessary to
    turn on the UserTransaction in a stateful session bean with BMT? If this
    doesn't happen, isn't
    there a danger, if the bean allows transactions to span business method
    invocations, that the
    container will passivate the bean while a transaction is active? Since the PM
    can't be saved during
    passivation, the tx would be interrupted by passivation -- something that
    would not happen if the
    container were aware that a tx was active.
    David Ezzio--
    Patrick Linskey [email protected]
    SolarMetric Inc. http://www.solarmetric.com

  • Using EJB remote session beans llike webservice.

    My requirement is to fetch a big size ASCII stream file from a remote location. For this can I use Statless EJB Session beans?
    For this EJB application & Web application will be on my application server side & EJB client should reside on the remote end side from where I want to fetch the file. - Please confirm my this logic as I am new in Java & EJB, I am having a basic query like this. (I don't want to proceed with EJB web service like (@Stateless, @WebService), I want to purly use EJB Statless Remote session beans - Is this possible?
    If yes, can I have one sample example URL pls?
    Thanks in advance for your help.

    My requirement is to fetch a big size ASCII stream file from a remote location. For this can I use Statless EJB Session beans?
    For this EJB application & Web application will be on my application server side & EJB client should reside on the remote end side from where I want to fetch the file. - Please confirm my this logic as I am new in Java & EJB, I am having a basic query like this. (I don't want to proceed with EJB web service like (@Stateless, @WebService), I want to purly use EJB Statless Remote session beans - Is this possible?
    If yes, can I have one sample example URL pls?
    Thanks in advance for your help.

  • Example of using session bean with webservices

    Hello,
    I am working with netbeans 5.5 (with JAX-WS 2.0 library) and using Tomcat.
    I have created webservices and everything is working well so far. However, each webservice is making a connection to my database.
    I would like to use a session bean so that I make the connection only once (at the begining of the client session for example) and store it into my session bean.
    I am a newbie in those things, I search on the Web and on this forum some code examples. The only thing I have found is this article http://weblogs.java.net/blog/ramapulavarthi/archive/2006/06/maintaining_ses.html
    When I tried this, the session doesn't seem to work at all : I get the same result (counter=1) twice.
    Does anybody have a complete example of how to use a session with webservices please?
    Thanks a lot!

    Sorry, I was not very clear in my last message.
    I need all my webservices to share the same bean during one user session.
    Then, if a page calls 2 different web services, only 1 database connection is made instead of 2. And if the user opens other pages which call other webservices, they will use the connection kept into the session bean.
    Anyway, I tried to do like it is said in your website but I can not build my project. I have an error : java.lang.LinkageError: JAXB 2.0 API is being loaded from the bootstrap classloader, but this RI (from jar:file:/C:/.../build/web/WEB-INF/lib/jaxb-impl.jar!/com/sun/xml/bind/v2/model/impl/ModelBuilder.class) needs 2.1 API. Use the endorsed directory mechanism to place jaxb-api.jar in the bootstrap classloader. I do not understand because I have downloaded the jax-ws 2.1.1 api and no other libraries are imported in my project. :-(
    I wonder if it is not related to netbeans...

  • Creating and deploying ejb 3.0 session bean with annotated pojo

    I try to create and deploy a EJB 3.0 stateless session bean (and associated webservice) with the following steps:
    1) Create Interface "Repository"
    package de.xxx.config;
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    import javax.jws.WebMethod;
    import javax.jws.WebService;
    @WebService
    public interface Repository extends Remote {
         @WebMethod(operationName = "findCampaignByChannel")
         public String findCampaignByChannel(String channelName) throws RemoteException;
    2) create dummy "RepositoryImpl"
    package de.xxx.config;
    import java.rmi.RemoteException;
    import javax.ejb.Stateless;
    import javax.jws.WebService;
    @WebService(endpointInterface="de.xxx.config.Repository")
    @Stateless
    public class RepositoryImpl implements Repository {
         public String findCampaignByChannel(String channelName) throws RemoteException {
              return null;
    3) The two class files are packaged into a jar without any further descriptors
    4) The jar is deployed with admin_client into the oc4j instance using the commands:
    -deploy -file <jarfile> -deploymentName <name>
    Result:
    An ear was constructed and started but no session bean or webservice is found (using the console). But according to to the docs a jar file without a ejb-jar.xml should be recognized as a EJB 3.0 ejb-jar file and the necessary steps to create session bean and expose webservice should be done automatically.
    My question:
    Which step do i miss here ?
    Tools used:
    Eclipse 3.2 for the jar file
    SoaSuite 10.1.3.1 for oc4j

    another strange problem.
    i have an APplication server added ( JBOSS ).
    when i create deployment profile (EAR ) application server is showed in the ComboBox .
    But when i create Java Test Client for some EJB and when i check " Connect Remote Application server" there is 2 comboboxes
    J2EE Application
    App Server Connection.
    first combo is ok there is EJB applicaiton
    Secound is empty .. but i Have App Server.
    Another think is that when i create EJB 3.0 its BAD to see J2EE app it must be J EE 5 app or just Java EE app

  • How to cast back and use a retrieved Session Bean reference in a servlet?

    Please help!
    1. I invoke a Session Bean from a servlet :
    travelagent = home.create();
    2. I store the travelagent reference in the HTTP Session :
    session.setAttribute( "travelagent" , travelagent );------------------------------------------------------------------------------------------------------------------
    Now, in another servlet, I have to retrieve the reference to the EJB from the HTTPSession.
    I then have to use this reference to call a business method in the EJB Session Bean.
    I have tried two ways to retrieve the reference and cast it before calling the business method. I get errors in both forms of casting.
    The Values you will see below in the code:
    EJB Remote Interface : TravelAgent (TravelAgent.java)
    Business Method : listItineraries( )
    Servlet which calls the above method : ListItinerary.java
    Line 46 of ListItinerary.java : ArrayList itineraries = traveler.listItineraries();------------------------------------------------------------------------------------------------------------------
    The two ways along with the error I get on the servlet page in the browser are :
    (A)
    TravelAgent traveler = (TravelAgent)session.getAttribute("travelagent");The error I get is :
    java.rmi.NoSuchObjectException: CORBA OBJECT_NOT_EXIST 9998 Maybe; nested exception is:
         org.omg.CORBA.OBJECT_NOT_EXIST: vmcid: 0x2000 minor code: 1806 completed: Maybe
    com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:208)
         com.sun.corba.ee.impl.javax.rmi.CORBA.Util.wrapException(Util.java:591)
         javax.rmi.CORBA.Util.wrapException(Util.java:277)
         source.traveler.ejb._TravelAgent_Stub.listItineraries(Unknown Source)
         source.traveler.servlet.ListItinerary.processRequest(ListItinerary.java:46)
    (B)
    TravelAgent traveler  =
    (TravelAgent)PortableRemoteObject.narrow(session.getAttribute("travelagent"), TravelAgent.class);The error I get is :
    java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
         java.rmi.RemoteException
         com.sun.corba.ee.impl.javax.rmi.CORBA.Util.wrapException(Util.java:597)
         javax.rmi.CORBA.Util.wrapException(Util.java:277)
         source.traveler.ejb._TravelAgent_Stub.listItineraries(Unknown Source)
         source.traveler.servlet.ListItinerary.processRequest(ListItinerary.java:46)
    Could someone advice on how to retrieve and cast the EJBObject's reference from the servlet so that I may use it to call the business method?
    Thanks!

    Thanks guys! It worked.
    1.. I should have used the handle. Got to coding without going deep in the concepts.
    2.. I dont know if I could have used the EJB Reference directly (instead of the handle).
    3.. The error was due to me not mapping the servlets with the EJBs that they could use. I continued to get the same error even after using the handle. Once I put the mapping to the EJBs correctly, everything fell in place.
    Thanks a lot!
    Henry

  • Session bean with 2 entity bean

    i have a phonebook manager (session bean) taht controls the category of contacts such as group a , group b, group c and group d. where group a b c and d are all entity beans.
    may i know how to control a session bean so that it can diferent which entity beans to invoke ?

    Group might be a table in a database,
    GroupEJB referes to Entity Bean.
    with the following fields. Group Id , Group disciption. where group ID is primary Key.
    Use a session bean and create your group A B C D.( EJB create method).
    Simple i guess.
    Enjoy
    Zoha.

  • When to use ApplicationBean  and Session Bean dataproviders

    hi i am developing a small application, in which i have cached rowset and if i want to access the database i have to call the bean component so which one to call either application Bean or Session Bean component in some examples they used application bean and in some applications they used session bean. Please suggest me the right one and i have to access the database correctly. I am confused ,please help me out in solving this problem.
    Thanking You in Advance.

    The following excerpt is from http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/scopes.html
    Before you create a bean property to store a value, you must decide what scope to put the property in. Because several users can access a web application at the same time, you want to use the smallest scope possible so that you don't waste valuable space. The following figure illustrates the duration of each type of scope.
    * Application scope lasts until the server stops the application. Values that you store in an application bean are available to every session and every request that uses the same application map.
    * Session scope begins when a user first accesses a page in the web application and ends when the session times out due to inactivity, or when the web application invalidates the session, such as, for example, by calling session.invalidate().
    * Request scope begins when the user submits the page and ends when the response is fully rendered, whatever page that is.

  • How to use Hibernet in session bean

    Hello all,
    i want to develop a Web client and a dextop client using hibernet technology....
    Is it possible to use session bean for connection to the database using hibernet.
    regards
    chetan

    Hi,
    Do you mean Hibernate ?
    if so, sure, you can use it from SessionBean.
    Regards,
    Sebastien Degardin.

  • Session Bean with WSAD 5

    I am able to write a session bean in WSAD. But I do not know how to run this in WSAD 5.0.
    Is there any tutorial available how to run session bean in WSAD 5.0? Or can any one explain??
    Thanks a lot in advance.

    Hi,
    You can use the bean explorer.
    You right click the bean in the J2EE Hierachy view(on the left) and click "Run on server" from the popup menu. This will start a server, you will need to put in a few configuration details, normally you should accept all the defaults. You'll see the Universal Test Client open once the server is running, like a browser where the Java editor is. If you don't then in the Servers view(at the bottom) right click the server that is started and select "Run universal test client". In the Universal Test Client window(i.e. the browser) click the ejb link then navigate to your bean. I think it is pretty self explainatory from here, but if you need a little more help try this link although it is a little reading to find what you want - http://publib.boulder.ibm.com/infocenter/wsphelp/index.jsp?topic=/com.ibm.etools.websphere.tools.common.doc/concepts/cwejbtc.htm .
    See ya
    Michael

  • Need urgent help: how to avoid concurrent calls on statefull session beans

    Hi,
    I need a little advice in designing a EJB session facade using JSPs, servlets, session and
    entity beans.
    My current design is:
    - JSP pages: here are only getMethods for the session bean used. All set-methods are handled by a
    - servlet: I have got one servlet handling several JSP pages. The servlet basically takes the
    form fields and stores them in the session bean and than dispatches to the next JSP-page
    - stateful session bean: here is, where all the business logic is conducted. There is one session
    bean per servlet using several
    - CMP entity beans: to talk to the database (Oracle 8i)
    The application server is JBoss 3.0.3.
    My problem is, if a user clicks on a submit button of a JSP page more than once before the next
    page builds up, I may get a "javax.ejb.EJBException: Application Error: no concurrent calls on
    stateful beans" error. I already synchronized (by the "session") the code in the servlet, but
    it happens in the JSP pages as well.
    I know, that Weblogic is able to handle concurrent calls, by JBoss isn't and it's clearly stated
    in the spec, that a user should avoid to have concurrent calls to a stateful bean.
    The big question is now: How can I avoid this? How can I prohibit the user to submit a form several
    times or to ignore anything, which arrives after the first submit?
    Thanks for any help,
    Thorsten.

    Synchronizing on the session is probably your best bet.
    You'll need to do all the data access and manipulation in the servlet. Cache any data you need using request.setAttribute() and then not access the EJB on the JSP page.
    If performance is an issue, you may also want to use create a user transaction to wrap all the EJB access in, otherwise each EJB call from the servlet is a new transaction. Just make sure you use a finally block to properly commit/rollback the transaction before you redirect to the JSP.
    UserTransaction utx    = null;
    synchronized (request.getSession())
      try {
        Context ctx = new InitialContext();
        utx = (UserTransaction) ctx.lookup("javax/transaction/UserTransaction");
        utx.begin();
        // ... Create session bean ...
        request.setAttribute("mydata", sessionBean.getMyData());
        try {
          utx.commit();
        catch (Exception ex) {
          log.warn("Transaction Rolled Back (" + ex.getClass().getName() + "): "
            + ex.getMessage(), ex);
        utx = null;
      } // try
      finally {
        if(utx != null)
          try {
            utx.rollback();
          catch (Exception e) {
            log.warn(e.getMessage(), e);
          } // catch
        } // if
      } // finally
    } // syncrhonized(session)

  • Deploying session beans with weblogic 5.1 in NT

    Hello ,
    I have a problem with deploying session beans in weblogic 5.0. I have
    written the code and compiled it. My Compilation is fine. Cud any one give
    me a step by step of how I should deploy my bean with weblogic 5.0 on
    windows NT.
    Raj Urs

    Hello ,
    I have a problem with deploying session beans in weblogic 5.0. I have
    written the code and compiled it. My Compilation is fine. Cud any one give
    me a step by step of how I should deploy my bean with weblogic 5.0 on
    windows NT.
    Raj Urs

  • Statefull session bean and MDB architecture

    Hello members,
    I'm planning to design an application in the following manner but not sure if that's the best design. Your input would be greatly appreciated.
    I have a stateful session bean (is also a MessageListener) which takes an order, sends the order to a MDB (which processes it by saving it to database and returns some search results). Then the MDB sends the search results as a message back to the stateful session bean.
    This seems to work fine, but I'm not sure whether I'm violating any of the J2EE specs.
    Thanks for your response,
    -a

    thanks.
    the reason i was asking these questions was i was playing with a stateless session bean that displays a jframe. i download from a jsp, and then close the browser, the jframe continues to function. i have not gotton deeper into functionality yet but i wonder if this poses a security problem: can this frame access the local computer system and do bad things? since it lives outside the browser, it appears dangerous.
    another interesting thing is when i close the frame, it shuts down the app server, even when i set the jframe to do nothing on exit. can you shed some light on this?

  • Button action with onclick in a jsp page using Jscript

    hi,
    I am facing a problem in setting an action with a button in a jsp page the error is object does'nt support this function,kindly send me reply as soon as possible.
    Santhosh

    hi,
    I am facing a problem in setting an action with a button in a jsp page the error is object does'nt support this function,kindly send me reply as soon as possible.
    Santhosh

Maybe you are looking for