aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes EJB DI in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "EJB DI in JSP" Watch "EJB DI in JSP" New topic
Author

EJB DI in JSP

lalit upadheyay
Ranch Hand

Joined: Jun 20, 2005
Posts: 110
Hi Ranchers,


My stateless session bean(FooBean) has only @Stateless annotation. My JSP (di_foo_test.jsp) simply has @EJB annotation for injecting the remote biz interface(FooRemote) annotated with @Remote.

I have index.htm as:


I have di_foo_test.jsp defined as:


My web.xml contains


I tried deploying the ejb-jar(foo.jar) first and foowebapp.war next in glassfish. Then when I hit index.htm and submit some message, I got org.apache.jasper.JasperException: java.lang.NullPointerException. I checked logs and found following:

[#|2009-07-25T08:48:42.343+0530|SEVERE|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=16;_ThreadName=httpSSLWorkerThread-8080-1;_RequestID=c70c606b-697b-4da0-a9cd-074c932a7a0f;|StandardWrapperValve[EJBTestJsp]: PWC1406: Servlet.service() for servlet EJBTestJsp threw exception
java.lang.NullPointerException
at org.apache.jsp.di_005ffoo_005ftest_jsp._jspService(di_005ffoo_005ftest_jsp.java:58)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:93)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
...
...
...

Then I undeployed both the ejb-jar and webapp. Created fooapp.ear containing foo.jar and foowebapp.war. Deployed it in glassfish. Tried to access my EJB client via http://localhost:8080/foowebapp . Tried to send some message via index.htm, but still getting the same error.

1. Can some one explain me what's going wrong? The DI works fine if I create a servlet EJb client(FooServlet ).

2. Inspired by succesful EJB DI in jsp in the posting http://www.coderanch.com/t/414899/EJB-Other-Java-EE-Technologies/java/Glassfish-EJB-web-client-EJB , I am very much keen to see it working. But despite lots n lots of attempts getting failures. Please help ?

3. In the posting Raf Szczypiorski, stated "one has to specify the jsp explicitly in web.xml for injection to work". Is it true ? Doesn't seem to work for me.

FYI, I am using Sun Java System Application Server 9.1_02 (build b04-fcs) installed via(glassfish-installer-v2ur2-b04-windows.jar) and JDK1.5.0.11 .


SCJP1.4, SCWCD1.4, SCBCD5.0(working on...)
lalit upadheyay
Ranch Hand

Joined: Jun 20, 2005
Posts: 110
Volunteers please suggest.. . I am hopeful that some courageous rancher has succesfully overcome this situation.
lalit upadheyay
Ranch Hand

Joined: Jun 20, 2005
Posts: 110
May I request the mdoerator to please move this posting to SCBCD forum where it might attract attention and get some response. I don't want to craete a duplicate Posting for the same.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10059
    
163

What happens when you try to access the di_foo_test.jsp directly instead of going through index.html? Also which exact version of Glassfish do you use? Are you sure that, that version supports injection in JSP? The other post shows that mapping a JSP in the web.xml does indeed help with the injection.

[My Blog] [JavaRanch Journal]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10059
    
163

lalit upadheyay wrote:May I request the mdoerator to please move this posting to SCBCD forum where it might attract attention and get some response.


Since this post has been in the EJB forum for quite some time now, i think its worth trying it in the SCBCD forum. Moving.
lalit upadheyay
Ranch Hand

Joined: Jun 20, 2005
Posts: 110
What happens when you try to access the di_foo_test.jsp directly instead of going through index.html?


If I try to access the di_foo_test.jsp directly by specifying url as http://localhost:8080/foowebapp/di_foo_test.jsp?msg=hello , still I get the same error messages (java.lang.NullPointerException) in response.

which exact version of Glassfish do you use?

How do I check the exact version of glassfish ? I looked at the console after bringing up the server and clicking the version tab in glassfish admin console. From that I concluded that I am using Sun Java System Application Server 9.1_02 (build b04-fcs). I installed glassfish via glassfish-installer-v2ur2-b04-windows.jar. I am using JDK1.5.0.11 .

Are you sure that, that version supports injection in JSP?

Not sure. But DI does work in a Servlet. I have verified that myself. The post url which I mentioned does not mention the version of glassfish used .
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332
EJB 3 in Action, page 440. - there is a table on top of page, which lists JSPs and helper classes as non-managed, and therefore injection doesn't work for them.
I'll try to find this in ejb core spec. to confirm it.
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332
from javaserver_pages_2_1.pdf spec.

JSP.7.1.11 Resource Injection

A JSP container that is not part of a Java EE technology-compliant
implementation is encouraged, but not required, to support resource injection.
Resource injection is not supported for JSP pages or tag files.


Note, that tag handler and event listeners are supported.
I think, that you have no other choice but to use JNDI in JSPs.
lalit upadheyay
Ranch Hand

Joined: Jun 20, 2005
Posts: 110
Hi John,

Thanks for highlighting the useful infnormtaion from core specs and providing reference to confirm that JSPs and helper classes as non-managed.

Inspired by succesful EJB DI in JSP in the posting http://www.coderanch.com/t/414899/EJB-Other-Java-E...a/Glassfish-EJB-web-client-EJB , I am very much keen to see it working. But despite lots n lots of attempts getting failures.

In this posting the author(Raf Szczypiorski) was finally succesful in injecting EJB in a JSP using GlassFish server. I am unable to find out the missing link in my repeated efforts to see it working. Also sent a private message to the author but didn't hear back anything.

Once again thanks for replying and sharing the information.
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332
I found another interesting workaround: http://markmail.org/message/awl7ae3uz43tnv2i

 
wood burning stoves
 
subject: EJB DI in JSP