• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB DI in JSP

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 https://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 .
 
lalit upadheyay
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Volunteers please suggest.. . I am hopeful that some courageous rancher has succesfully overcome this situation.
 
lalit upadheyay
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 .
 
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 https://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
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found another interesting workaround: http://markmail.org/message/awl7ae3uz43tnv2i

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic