Solved

Need JSP, EJB, and database example

Posted on 2004-10-15
7
899 Views
Last Modified: 2010-04-01
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.
0
Comment
Question by:skip1000
  • 3
  • 2
  • 2
7 Comments
 
LVL 14

Assisted Solution

by:boonleng
boonleng earned 50 total points
ID: 12326675
Have you read the J2EE blueprints?
http://java.sun.com/blueprints/patterns/index.html 
http://java.sun.com/blueprints/corej2eepatterns/Patterns/index.html

It provides the J2EE structure/pattern and shows how all the components connected to each others.
There's many sample codes and for you case you would be looking at Business Delegate and Service Locator.

Demo:
http://java.sun.com/blueprints/code/index.html#java_pet_store_demo
0
 

Author Comment

by:skip1000
ID: 12331592
I took a look at the petstore project included w/ J2EE bundle.  The app was really too huge for my purpose.  It also did not have any example of how JSP would reference an EJB to perform select, insert, update, and delete on a database.  I haven't any success finding such an example yet.

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
0
 
LVL 13

Accepted Solution

by:
petmagdy earned 450 total points
ID: 12332454
If u want a small sample on oracle database for JSP calling BMP EJB provide me with ur email and i can send u a clear sample
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:skip1000
ID: 12332691
Hi petmagdy,

Pls send code to the following address johnstone59@yahoo.com.  Thanks.
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12333701
I will send it to u with instructions
0
 
LVL 14

Expert Comment

by:boonleng
ID: 12336559
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
0
 

Author Comment

by:skip1000
ID: 12366275
Here's the sample code of jsp to access entitiy ejb:

<%@ page  language="java"  
import="javax.ejb.*, javax.naming.*, examples.ejb20.basic.beanManaged.*, 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/Account");
                  accounts = accountLocalHome.findBigAccounts(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><%=accountLocal.getAccountId() %></b></td>
    <td width="30%" align="center"><b><%=accountLocal.balance() %></b></td>
  </tr>

<%
      }
    }
%>
  </body>
</html>
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
Note: This is the third blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   We’ve been talki…
A short film showing how OnPage and Connectwise integration works.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now