• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JSP as EJB client (Urgent!)

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Noreen Masterson
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic