ejb access

Hi,

I'm currently trying to get to know Java EE and thus playing around a little. But off course this means some trouble can happen along the road...

I created an EJB called TitleCheckerBean with a local interface TitleCheckerLocal which I can use without problems in a servlet like this:

publicclass PostMessageextends HttpServlet{

@EJB

private TitleCheckerLocal titleChecker;

...

if (!titleChecker.checkTitle(e)){

response.sendRedirect("invalidMessage.jsp");

}else{ ...

However, I tried doing the same using JSP and the following code but with a more negative result:

initCtx =new InitialContext();

TitleCheckerLocal titleChecker = (TitleCheckerLocal)initCtx.lookup("java:comp/env/ejb/TitleCheckerLocal");

ConnectionFactory connectionFactory = (ConnectionFactory)initCtx.lookup("jms/NewMessageFactory");

Queue queue = (Queue)initCtx.lookup("jms/NewMessage");

Using this code, I get:

javax.naming.NameNotFoundException: No object bound to name java:comp/env/ejb/TitleCheckerLocal

However, my ConnectionFactory and Queue pose no problems.

So the question is what am I forgetting to do, because I read in numerous threads that to access an EJB from a JSP this is the way to go, but obviously not in my case. I suppose the @EJB annotation used in the servlet is doing some 'under the hood magic' that is not happening in the JSP case, but which kind of magic?

Is there maybe some *.xml I also need to change?

Thanks!

Vaak

[1997 byte] By [vAaka] at [2007-11-27 6:51:01]
# 1
Found it!Needed to add a ejb-local-ref tag in the web.xml deployment descriptor.Did that before, but with the wrong settings...does anybody have some good links or stuff that might help me understand these inner workings of the container?
vAaka at 2007-7-12 18:25:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi,

this thing keeps annoying me...

Referring to my first post in this thread, how come that in case of the JSP page, I need to add the ejb-local-ref in web.xml to resolve the lookup in JNDI, while this is not needed for the servlet case using the @EJB annotation?

As far as the code is concerned both cases get the same info (a local interface), but only for one of them it's enough to find which EJB is meant. Are they searching in different contexts or is the annotation doing some magic or ...

I hope I'm not blind to the obvious here!

Regards,

Vaak

vAaka at 2007-7-12 18:25:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...