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)
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 ).
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.
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 JDK184.108.40.206 .
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 .
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.
Joined: May 04, 2007
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.
Joined: Jun 20, 2005
Thanks for highlighting the useful infnormtaion from core specs and providing reference to confirm that JSPs and helper classes as non-managed.
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.