This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes JSP as EJB client (Urgent!) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP as EJB client (Urgent!)" Watch "JSP as EJB client (Urgent!)" New topic
Author

JSP as EJB client (Urgent!)

Noreen Masterson
Greenhorn

Joined: Apr 30, 2002
Posts: 16
Hi there
bit of a problem - i havent used JSP too much before this week - and i am trying to have one as a client to my session bean....except i dont really know how to go about it
can anyone give me some good tips on starting this, or point me to a good tutorial website?
I know how to do the server lookup to locate the home interface of the session but am unsure about setting up initialcontexts etc - would i be better having a bean to do this and then just start on integrating with the session beans?
This has to be done for tomorrow (3pm GMT) so finding out how to do it quickly is of the essence.
many thanx for any help
noreen
Sam Dalton
Author
Ranch Hand

Joined: Jul 26, 2001
Posts: 170
OK, there are several ways to do this. There is the quick way, and there is the (architecturally) correct way.
Being as how you have very little time to do this I suggest the quick way
There is not difference in accessing your EJB from a JSP page, than accessing it from a standalone application (which I assume you have done).
Here are (broadly) the steps:
1) Create you initial context
<%
Context context = new InitialContext();
2) Lookup your bean
Object obj= context.lookup("JNDI NAME");
BeanHome home=(BeanHome)PortableRemoteObject.narrow(obj,BeanHome.class);
3) Create your bean
Bean bean = home.create();
4) Use your bean
bean.aMethod();
%>
5) Remember to catch the relevant exceptions (NamingException, CreateException, RemoteException etc)
And that should be that. To do it in a better way, check out the J2EE Patterns for alternative methods.
Hope this helps
Rgds
Sam


<a href="http://www.samjdalton.com" target="_blank" rel="nofollow">Sam Dalton</a>,<br />Co-author of [http://www.amazon.com/exec/obidos/tg/detail/-/1590592255/qid=1068633302//ref=sr_8_xs_ap_i0_xgl14/104-4904002-9274339?v=glance&s=books&n=507846]Professional JSP 2.0[/URL] (October 2003)<br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/1861007701/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional SCWCD Certification</a><br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/186100561X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional Java Servlets 2.3</a>
Noreen Masterson
Greenhorn

Joined: Apr 30, 2002
Posts: 16
yes, this looks very much as i thought it would...
however our bean is deployed onto the IBM Websphere Server adn we are using the Webspher commerce suite.
and it seems the jar must be placed into a specific directory -- but i would also assume it needs to be added to a classpath (or some such) that will let the server know to load it....?
any ideas?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JSP as EJB client (Urgent!)
 
Similar Threads
Stateful session bean -- clarification urgent
How to manage the session for GUI and Web client
calling a web service from a session bean
EJB3 Doubts
Stateful Session Bean -- clarification urgent