NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Call EJB from JSP page

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
ianaz



Joined: 07 Apr 2009
Posts: 1

PostPosted: Tue Apr 07, 2009 7:12 am    Post subject: Call EJB from JSP page Reply with quote

Hi all,

I've a question about the article http://www.netbeans.org/kb/55/ejb30.html#Exercise_3


I call without problems the EJB methods from a servlet because I have the variable
Code:

    @EJB
    private CategoriaFacadeLocal categoriaFacade;


But I need in a simple jsp page. How can I access to the bean?

Thanks in advance


P.S: Sorry for the double post


Last edited by ianaz on Tue Apr 07, 2009 7:19 am; edited 1 time in total
Back to top
Silvio Rainoldi
Posted via mailing list.





PostPosted: Tue Apr 07, 2009 7:16 am    Post subject: Call EJB from JSP page Reply with quote

Hi all,

I've a question about the article http://www.netbeans.org/kb/55/ejb30.html#Exercise_3


I call without problems the EJB methods from a servlet because I have the variable
[code:1:9f637150c4]
Back to top
Jindrich Sedek
Posted via mailing list.





PostPosted: Tue Apr 07, 2009 7:54 am    Post subject: Call EJB from JSP page Reply with quote

Hi,

You can use JSP declaration to declare a variable in the same way as you
do in servelts:

<%! @javax.ejb.EJB CategoriaFacadeLocal categoriaFacade; %>

You will need to user full package name or use imports:

<%@page import="" %>


Jindra

Silvio Rainoldi wrote:
Quote:
Hi all,

I've a question about the article
http://www.netbeans.org/kb/55/ejb30.html#Exercise_3


I call without problems the EJB methods from a servlet because I have
the variable
Code:

@EJB
private CategoriaFacadeLocal categoriaFacade;


But I need in a simple jsp page. How can I access to the bean?

Thanks in advance
Back to top
ianaz
Posted via mailing list.





PostPosted: Tue Apr 07, 2009 8:29 am    Post subject: Call EJB from JSP page Reply with quote

Thanks for your reply; but it don't work.

The code:


Back to top
Daoud AbdelMonem Faleh
Posted via mailing list.





PostPosted: Tue Apr 07, 2009 1:45 pm    Post subject: Call EJB from JSP page Reply with quote

You have to lookup the EJB before using it otherwise it's still null

InitialContext ctx = new InitialContext();
CategoriaFacade cat = (CategoriaFacadeLocal)
ctx.lookup("java:comp/env/ejb/CategoriaFacadeLocal");
cat.findAll();

HTH,
Daoud AbdelMonem Faleh.

ianaz a
Back to top
ianaz
Posted via mailing list.





PostPosted: Tue Apr 07, 2009 2:52 pm    Post subject: Call EJB from JSP page Reply with quote

Hi Daoud AbdelMonem Faleh,
thanks for your reply.

It give me an exception:

javax.naming.NameNotFoundException: No object bound to name
java:comp/env/ejb/CategoriaFacadeLocal

Where can i "bound" my CategoriaFacadeLocal?
I've tried to declare in web.xml; doesn't work!
I have not others xml (ejb-jar.xml,...)

Thanks


2009/4/7 Daoud AbdelMonem Faleh <address-removed>:
Quote:
You have to lookup the EJB before using it otherwise it's still null

InitialContext ctx = new InitialContext();
Back to top
bassem.ali33
Posted via mailing list.





PostPosted: Tue Apr 07, 2009 3:06 pm    Post subject: Call EJB from JSP page Reply with quote

Hello
You must deploy ejb with jsp on same package as EAR application to use ejb
as local.

-----Original Message-----
From: ianaz [mailto:address-removed]
Sent: Tuesday, April 07, 2009 4:53 PM
To: address-removed
Subject: Re: [nbj2ee] Call EJB from JSP page

Hi Daoud AbdelMonem Faleh,
thanks for your reply.

It give me an exception:

javax.naming.NameNotFoundException: No object bound to name
java:comp/env/ejb/CategoriaFacadeLocal

Where can i "bound" my CategoriaFacadeLocal?
I've tried to declare in web.xml; doesn't work!
I have not others xml (ejb-jar.xml,...)

Thanks


2009/4/7 Daoud AbdelMonem Faleh <address-removed>:
Quote:
You have to lookup the EJB before using it otherwise it's still null

InitialContext ctx = new InitialContext();
Back to top
ianaz
Posted via mailing list.





PostPosted: Tue Apr 07, 2009 3:10 pm    Post subject: Call EJB from JSP page Reply with quote

Solved:


In web.xml:

<ejb-local-ref>
<ejb-ref-name>CategoriaEJB</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home/>
<local>org.ianaz.session.CategoriaFacadeLocal</local>
</ejb-local-ref>



In index.jsp (the jsp page)

InitialContext ctx = new InitialContext();
CategoriaFacadeLocal cat = (CategoriaFacadeLocal)
ctx.lookup("java:comp/env/CategoriaEJB");




Thanks very much to all!!! Thanks thanks and thanks!
Java the best!
Back to top
nestor gomez munoz
Posted via mailing list.





PostPosted: Wed Apr 08, 2009 12:38 am    Post subject: Call EJB from JSP page Reply with quote

Hi! I supose this link may help you. I'm just looking about this topic
but can't give you much details by the moment.

https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB

El mar, 07-04-2009 a las 07:12 +0000, ianaz escribió:
Quote:
Hi all,



I've a question about the article http://www.netbeans.org/kb/55/ejb30.html#Exercise_3





I call without problems the EJB methods from a servlet because I have the variable


Code:


@EJB

private CategoriaFacadeLocal categoriaFacade;





But I need in a simple jsp page. How can I access to the bean?



Thanks in advance



Back to top
Muhammad Hamaad Latif



Joined: 14 Oct 2017
Posts: 0

PostPosted: Sat Oct 14, 2017 12:08 pm    Post subject: netbeans Reply with quote

You need to remember that in the world everything should be possible like you can have imvu hack online for get free imvu credits online and it is not a joke at all go over there and get in a simple way.
Back to top
priya465



Joined: 17 Aug 2017
Posts: 30

PostPosted: Tue Nov 14, 2017 6:50 am    Post subject: Reply with quote

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...
%>
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo