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,AccountHome.class);
}
%>
<%
//instantiate the session bean
Account acct = accHome.create();
//invoke the remote methods
acct.doWhatever(...);
// etc etc...
%>
What is the most efficient approach for integrating EJB with JSP? Should the
EJBs be invoked directly from within JSP scriptlets? Should the access take
place from within Java beans? Or is it best to use custom tags for this
purpose?
1) JSP scriptlet code should be minimal. Invoking EJB code directly on a JSP
page results in many lines of code on your JSP page, including try...catch
blocks to catch naming and finding exceptions.
2) Using a standard JavaBean as an intermediary between the JSP page and EJB
server cuts down on the amount of code needed to add to a JSP page, and
promotes reuse. The JavaBean should be a simple wrapper around the EJB you
are accessing.
If you use a standard JavaBean you could also use the jsp:useBean tag to
setup EJB parameters, such as the server URL and server security parameters.
3)Custom tags are also an option. However, they require a lot more coding
than a simple JavaBean wrapper. The point should be to rewrite as little
code as possible while at the same time keeping the JSP scriptlet content as
light as possible
----- Original Message -----
From: "EJB Vikas" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, January 14, 2001 10:51 PM
Subject: EJB from JSP
> Hi!
>
> I am using Weblogic to run my JSP, I want to access the EJB deployed in
> weblogic from my JSP. How can I do that???
> Any Links!!!!
> Any codes!!!!!
> TIA
> Bye!
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff EJB-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
>
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".