This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes EJB and other Java EE Technologies and the fly likes Accsessing EJB in the web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Accsessing EJB in the web application" Watch "Accsessing EJB in the web application" New topic
Author

Accsessing EJB in the web application

Alka S.
Greenhorn

Joined: Nov 29, 2003
Posts: 26
I am using Tomcat as web server and Weblogic as application server.
I have deployed EJBs on Weblogic. I have to use these EJBs in Jsps (Action classes). Code is as follows
As MVC architecture I am calling EJB in ction class
public ActionForward execute(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
{
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "tc://localhost:7001");
Context initCtx = new InitialContext(p);
Object obj = initCtx.lookup("myFacilityService");
FacilityServiceHome home = (FacilityServiceHome)PortableRemoteObject.narrow(obj,
FacilityServiceHome.class);
//Create the remote interface instance
FacilityService cli = home.create();
cli.getAllFacility();
httpServletRequest.setAttribute("FacilityList", cli.getAllFacility());
}
In jsp
Integer val = (Integer)request.getAttribute("FacilityList");
String counrVal = " ";
if (val != null)
counrVal = val.toString();
I have copied ejb jar file which is deployed on weblogic on WEB_INF-lib folder and added in JBuilder for required libraries. It is coplling properly but while running it is giving erroras follows -
Error -----------------------------------Cannot instantiate class: weblogic.jndi
.WLInitialContextFactory
After copying weblogic.jar in Tomact - common - lib folder it is giving error null.
Can anybody knows the above problem?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accsessing EJB in the web application