skip1000
asked on
Need JSP, EJB, and database example
Hi,
I'm new to J2ee and I need to build an application that uses JSP, EJB (BMP entity bean), and datatabase, preferrably pointbase. I have been using examples from the J2EE tutorial (downloadable from Sun's website), such as the bookstore example (see bookstore2 example), but it uses javabean, not EJB. I've created the table I needed in pointbase (included w/ the J2EE 1.4) and I've created the EJB's. Now I just need help in making this all connect w/ JSP. Can anyone point me to a site w/ such examples for me me look at or show me sample JSP code that accesses data using EJB? Please include any deployment information that I also need to know about.
Since the examples I have been working with uses JSTL and not scripts, examples w/ JSTL would be better and less confusing.
Thanks.
I'm new to J2ee and I need to build an application that uses JSP, EJB (BMP entity bean), and datatabase, preferrably pointbase. I have been using examples from the J2EE tutorial (downloadable from Sun's website), such as the bookstore example (see bookstore2 example), but it uses javabean, not EJB. I've created the table I needed in pointbase (included w/ the J2EE 1.4) and I've created the EJB's. Now I just need help in making this all connect w/ JSP. Can anyone point me to a site w/ such examples for me me look at or show me sample JSP code that accesses data using EJB? Please include any deployment information that I also need to know about.
Since the examples I have been working with uses JSTL and not scripts, examples w/ JSTL would be better and less confusing.
Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi petmagdy,
Pls send code to the following address johnstone59@yahoo.com. Thanks.
Pls send code to the following address johnstone59@yahoo.com. Thanks.
I will send it to u with instructions
You can have JSP with entity EJB, but is not advisable.
JSP represent the view and entity bean represent the integration with the database(persistance layer), if use JSP to call entity bean means you have skip the control and business layer. This will expose the business logic (security issue), and wont be able to use the CMP features(tranasction management). This will also cause network overhead and performance degradation when calling multiple entity bean at the same time.
Regards,
Boon Leng
JSP represent the view and entity bean represent the integration with the database(persistance layer), if use JSP to call entity bean means you have skip the control and business layer. This will expose the business logic (security issue), and wont be able to use the CMP features(tranasction management). This will also cause network overhead and performance degradation when calling multiple entity bean at the same time.
Regards,
Boon Leng
ASKER
Here's the sample code of jsp to access entitiy ejb:
<%@ page language="java"
import="javax.ejb.*, javax.naming.*, examples.ejb20.basic.beanM anaged.*, java.util.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>untitled</title>
</head>
<%
Collection accounts = new Vector();
try
{
final InitialContext context = new InitialContext();
AccountLocalHome accountLocalHome = (AccountLocalHome) context.lookup("java:comp/ env/ejb/Ac count");
accounts = accountLocalHome.findBigAc counts(0.0 );
}
catch( Exception ex)
{
}
%>
<body>
<%
int itemsCount = accounts.size();
if(itemsCount == 0)
{
out.print("No Accounts were found!");
}
else
{
%>
<table border="0" width="100%">
<tr>
<td width="20%" align="center"><b>ID</b></ td>
<td width="30%" align="center"><b>BAL</b>< /td>
</tr>
<%
Iterator iterator = accounts.iterator();
while( iterator.hasNext() )
{
AccountLocal accountLocal = (AccountLocal) iterator.next();
%>
<table border="0" width="100%">
<tr>
<td width="20%" align="center"><b><%=accou ntLocal.ge tAccountId () %></b></td>
<td width="30%" align="center"><b><%=accou ntLocal.ba lance() %></b></td>
</tr>
<%
}
}
%>
</body>
</html>
<%@ page language="java"
import="javax.ejb.*, javax.naming.*, examples.ejb20.basic.beanM
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>untitled</title>
</head>
<%
Collection accounts = new Vector();
try
{
final InitialContext context = new InitialContext();
AccountLocalHome accountLocalHome = (AccountLocalHome) context.lookup("java:comp/
accounts = accountLocalHome.findBigAc
}
catch( Exception ex)
{
}
%>
<body>
<%
int itemsCount = accounts.size();
if(itemsCount == 0)
{
out.print("No Accounts were found!");
}
else
{
%>
<table border="0" width="100%">
<tr>
<td width="20%" align="center"><b>ID</b></
<td width="30%" align="center"><b>BAL</b><
</tr>
<%
Iterator iterator = accounts.iterator();
while( iterator.hasNext() )
{
AccountLocal accountLocal = (AccountLocal) iterator.next();
%>
<table border="0" width="100%">
<tr>
<td width="20%" align="center"><b><%=accou
<td width="30%" align="center"><b><%=accou
</tr>
<%
}
}
%>
</body>
</html>
ASKER
This poses a question: Does the real world use JSP w/ entity EJB to perform action on a databse? Can some present an example of how this is done, if such things exist? That's EJB, not javabean.
Thanks