473,387 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to call EJB's in JSP's

can i call EJB's in Jsp
Sep 12 '06 #1
8 11654
Assyst
4
can i call EJB's in Jsp

Yes , You can call EJB in JSP , Similar to how you call Java Beans in JSP
Sep 12 '06 #2
The following is a code snippet that demonstrates how a JSP page can interact with an EJB session bean:

<%@ page import="javax.naming.*, javax.rmi.PortableRemoteObject,
foo.AccountHome, foo.Account" %>
<%!
//declare a "global" reference to an instance of the home interface of the session bean
AccountHome accHome=null;

public void jspInit()
{
//obtain an instance of the home interface

InitialContext cntxt = new InitialContext( );
Object ref= cntxt.lookup("java:comp/env/ejb/AccountEJB");
accHome = (AccountHome)PortableRemoteObject.narrow(ref,Accou ntHome.class);
}
%>
<%
//instantiate the session bean

Account acct = accHome.create();
//invoke the remote methods

acct.doWhatever(...);
// etc etc...
%>
Feb 12 '07 #3
r035198x
13,262 8TB
The following is a code snippet that demonstrates how a JSP page can interact with an EJB session bean:

<%@ page import="javax.naming.*, javax.rmi.PortableRemoteObject,
foo.AccountHome, foo.Account" %>
<%!
//declare a "global" reference to an instance of the home interface of the session bean
AccountHome accHome=null;

public void jspInit()
{
//obtain an instance of the home interface

InitialContext cntxt = new InitialContext( );
Object ref= cntxt.lookup("java:comp/env/ejb/AccountEJB");
accHome = (AccountHome)PortableRemoteObject.narrow(ref,Accou ntHome.class);
}
%>
<%
//instantiate the session bean

Account acct = accHome.create();
//invoke the remote methods

acct.doWhatever(...);
// etc etc...
%>
Thanks for diiging this up
Feb 12 '07 #4
dmjpro
2,476 2GB
can u figure me out the j2ee and ejb in javaworld
Feb 12 '07 #5
r035198x
13,262 8TB
can u figure me out the j2ee and ejb in javaworld
What do you mean by this?
Feb 12 '07 #6
dmjpro
2,476 2GB
these two things are not clear to me ......
Feb 12 '07 #7
r035198x
13,262 8TB
these two things are not clear to me ......
You mean you don't understand what j2ee and ejb are?
Well the truth is I won't be able to explain both of them in one post.

J2EE is an architecture for making webservices and perhaps other types of systems as well. the difference with J2SE (which is the standard Java) is the presence of JSPs, Servlets (both of which can only run on a server) and the enterprise java beans(of which there are three types session, message and entity types.) Often the architecture uses JSPs for the front of the system (JSPs are HTML pages with Java code ambedded in them), Servlets for controlling the system (These are Java classes which run on a server), and ejbs for the business logic and storage of data. JSPs are actually compiled into Servlets first and so they have to run on the server as well. There is really much more to these things than I've said here.
Feb 12 '07 #8
dmjpro
2,476 2GB
that means ejb is a part of j2ee architecture ....

thanks fo ur reply .....
Feb 12 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Martin Zeigler | last post by:
I have been using Weblogic 5.1 for a couple of years. I currently pass an object as a parameter to my ejbCreate method. The data in the object could be modified by my bean and the caller needs to...
0
by: Steffen | last post by:
Hi! I'm trying to access a EntityBean from a servlet via the bean's local home interface. The EJB and the Servlet are together in one .ear file and I'm using JBoss 3.2.3. I think the...
1
by: harry | last post by:
I have a enterprise app constisting of 6 EJB's & 1 web component. I want one of the ejb's to control database persistance using the iBatis framework. Where do I put the jar files that make up...
1
by: mca2007 | last post by:
there is servlets and jsp concepts are there,so why we ejb's came to existance. normally we will be having facility to use beans in jsp.so why we use ejb.
0
by: praveen2gupta | last post by:
I have read many articles about ejb from various web sites and i am good in theorital part. But I am facing problems to implement It. Firstly I wants a sample EJB application code and steps to...
5
by: jith87 | last post by:
Hai, My proj has JSP @ the front end and MySql @ the back end. Server that i m gonna use is Apache Tomcat.My question is should i use JDBC or EJB to transmit the data from the front end to the...
0
by: star111792 | last post by:
helo all i am working with JSP and EJBs. i have written a simple code for verifying username and password of user by using session beans. my problem is that i am getting the following exception: ...
2
by: star111792 | last post by:
helo all, i am working with JSP and EJBs. i have written a simple code for verifying username and password of user by using session beans. my problem is that i m getting exception named...
3
oll3i
by: oll3i | last post by:
when i run my create.jsp that populates the database i get javax.ejb.EJBException error it throws the exception at line phoneHome.create("01", "01", "0957205114"); i have three lookups...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.