Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can't use <code>new</code> to get a new SFSB. </p> <p>What you typically do is to <code>lookup</code> a new one using the <code>InitialContext</code>. </p> <pre><code>MyBean bean = (MyBean) new InitialContext().lookup( name ); </code></pre> <p>You get then a reference to a specific SFSB that you can reuse across requests. </p> <p>From <a href="http://www.coderanch.com/t/318711/EJB-JEE/java/EJB-Lookup-or-inject-stateful" rel="nofollow noreferrer">this answer</a>:</p> <blockquote> <p>You should not typically inject SFSB, unless it is into another SFSB or into a Java EE client. You should use @EJB on the referencing class (e.g. your servlet) to declare the ejb-ref and then do a JNDI lookup in the code to obtain the instance. This instance could then be placed directly in your Http session.</p> </blockquote> <p>For more information about SFSB, you might be interested in these other answers from me:</p> <ul> <li><a href="https://stackoverflow.com/questions/2811312/stateful-ejbs-in-web-application/2811833#2811833">Stateful EJBs in web application?</a> </li> <li><a href="https://stackoverflow.com/questions/2808773/java-tracking-a-user-login-session-session-ejbs-vs-httpsession/2811086#2811086">Java: Tracking a user login session - Session EJBs vs HTTPSession</a> </li> <li><a href="https://stackoverflow.com/questions/1935178/correct-usage-of-stateful-beans-with-servlets/1935476#1935476">Correct usage of Stateful Beans with Servlets</a> </li> </ul> <p>Hope it helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload