File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Oracle/OAS and the fly likes exception accessing ejb from servlet in OCj4 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "exception accessing ejb from servlet in OCj4" Watch "exception accessing ejb from servlet in OCj4" New topic

exception accessing ejb from servlet in OCj4

Valerio De Minico

Joined: Jul 14, 2008
Posts: 1
I'm aving a problem accessing a stateful session bean from a servlet. I'm using a jndi lookup to do it because I need that a client has its own bean reference...

My code is:

and I have a reference to EJB into web.xml:


If I use @EJB annotation to inject the servlet, it works fine.
Instead using jndi lookup throws a NamingException because it doesn't find java:comp/env/ejb/Carrello entry.

Any idea about the problem?

[edit]Add code tags. CR[/edit]
[ July 14, 2008: Message edited by: Campbell Ritchie ]
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1138

Pardon me if I am stating the obvious, but first of all, in order to lookup an EJB from a servlet, both the EJB and servlet usually need to be in the same EAR, i.e. same JEE application.
Also, it looks like you are using the EJB's local interface, in which case I believe your lookup string is wrong.
I don't recall the correct format, but I believe it is detailed in the OC4J documentation, which is available from:

Good Luck,
It is sorta covered in the JavaRanch Style Guide.
subject: exception accessing ejb from servlet in OCj4
jQuery in Action, 3rd edition