tags:

views:

141

answers:

2

Hi!

I'm new to ejb. Actually I've created one ejb and I added reference to a web application which will call the session bean simply. How to call the session bean from the jsp file?

A: 

1) the first way will be to create a direct object

use import tag to import ur class

< % @ page import = packageName.Classname %>
    <%
    @EJB
    Classname object = new Classname();
    %>

and then access methods using normal jsp

<%=object.callmethod()%>

2) the other way will be to use standard actions

<jsp:useBean id="beanId' class="packagename.ClassName" />
<jsp:getStudentInfo name="beanId" property="name"/>
rgksugan
I'm using default package. So, how can I mention the package. Moreover when I tried with this two way, I'm getting the error as "Unable to compile class for JSP". I'm using netbeans...
Nila
@nilathere is no need to use the page import option in case u r using the same package.other things should work fine.
rgksugan
+1  A: 

I could also prefer you to use the MVC model for your application. In that case there is no need to call a session bean from the jsp, you can call it from the servlets itself.

Check out this link to call a EJB from a servlet. Click

rgksugan