File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes JBoss, EJB and JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JBoss, EJB and JSP" Watch "JBoss, EJB and JSP" New topic
Author

JBoss, EJB and JSP

Harry Singh
Ranch Hand

Joined: May 02, 2001
Posts: 124
HI Gurus,
Can someone tell me how to call EJB from jsp page in JBoss... i have tried using the same context.lookup technique but it didnt work.
Is there any other way of calling ejb components from JSP in JBoss, like in weblogic we can make tag library and can then deploy the war file.
Thanks in advance
Regards,
Harjinder
Mat Robinson
Greenhorn

Joined: Aug 02, 2002
Posts: 20
You might want to consider using a proxy object behind the JSP. Reference this object using the <jsp:useBean ..> tag and in the constructor of this object lookup the SessionBean.
Use this proxy object to delegate the requests from the JSP to the SessionBean behind it.
Have fun,
Mat.
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
Using the standard method of looking up EJBs does work from JSP pages - you just have to make sure that you import all the right classes.
As Mat says, you can use a proxy object, while another alternative is to use a custom tag to wrap up the JNDI lookup for you. Take a look at Chapter 8 : Tag Patterns (from Professional JSP Tag Libraries) for an example of how to achieve this.
These are all great ways to access EJBs from a JSP page, but are really suited to smaller applications because from an architectural perspective, accessing enterprise resources from JSP pages (the view components) tends to go against some of the best practices such as MVC, also known as the web application model 2 architecture, particularly for larger applications. In model 2, the view components are just that - responsible for presenting information held in the model.
Take a look at Chapter 12 : Designing Web Applications and Servlet Patterns (from Professional Java Servlets 2.3) for more information on the model 2 architecture.
Hope that's useful...
Simon
jawwad ahmed
Ranch Hand

Joined: Dec 01, 2001
Posts: 179
Hi;
Well it is a good practice to look up ejbobject via custom tag.
But if there is an href or submit button in your jsp page use mvc and in command class use ejbCommand pattern and in that serializable class of ejbCommand paterrn by using ejbhome factory pattern call ejb object.
Jawwwd Ahmed
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
Originally posted by jawwad ahmed:
Hi;
Well it is a good practice to look up ejbobject via custom tag.

Well, certainly better than all that nasty Java code embedded in the JSP.
Harry Singh
Ranch Hand

Joined: May 02, 2001
Posts: 124
Hi Gurus,
Thanks for the quick response.well actually i have just started EJB and i have done it using weblogic server where u can acces EJB from JSP using tag lib. but now i wanna do the same thing in JBoss, and i dont know how to make that proxy object and jndi look up.can u paste a sample code here as that will be easy for understanding.
Thanks in advance
Regards,
Harry
jawwad ahmed
Ranch Hand

Joined: Dec 01, 2001
Posts: 179
Well u can download free pdf and examples from sourceforge.net also documentation of 2.4 available on jboss.org/onlinemanual search from google.Frm that at least u can getstart.
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JBoss, EJB and JSP
 
Similar Threads
how to migrate EJB 2.1 from weblogic to JBOSS 5.x version
EJB deployment in jboss
Web Server and App Server!!!
Working with JBoss/Tomcat
benefits by integrating tomcat with jboss