cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing EJB Object in JSP, need help

Former Member
0 Kudos

Hi,

We have implemented EJB's in our Portal. We are having problems in accessing the EJB Object inside JSP. When we do a response.write in the Portal Component,we are able to get the values of the Object in JSP but when we access the EJB Object in JSP and try to get the values with the get methods, it fails, getting Unable to render JSP error.

Did anyone come across this kind of situation.

Any help is highly appreciate,

Thank you for your time.

Regards

Som

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

I think I mis-stated the problem. What we have is a simple POJO (Plain old Java Object) that implements Serializable. The portal component invokes a Stateless Session Bean which returns a POJO (this is done using the "SharingReference" property in the portal-app.xml). The portal component then stores the POJO in the HttpSession. We are trying to access the POJO in the JSP using something like

<% Person person = (Person) session.getAttribute("person"); %>

This is where it fails. Since it can't reference the "Person" class (the JSP contains the import of the package). The Person class is in a Java Project that's JAR(red) and available to the EJB Project. When we put the same JAR in the /PORTAL-INF/lib folder and invoked the JSP, we get a ClassCastException (since the object in the session is different than the one being referenced in the JSP). So the question is how can we pass the POJO across the EJB, Portal and JSP containers?

Former Member
0 Kudos

Hi Vasu,

I am able to access the EJb object in JSP and deployed JSP as a portal components also.

For this I have followed the following steps:

1. created the EJB component(MyEJB)deployed it in the WAS.

2. created a Portal Application(MyEJBPar.par file).

3. created a Portal Component ie. Abstract Portal Component.

4. copy the MyEJB.jar file to the MyEJBPar\dist\PORTAL-INF\lib folder.

5. created a JSP file(MYJSP.jsp) in the MyEJBPar\dist\PORTAL-INF\jsp folder.

in the JSP I have added the following code:

<%

try{

javax.naming.InitialContext ie=new javax.naming.InitialContext();

Object obj=ie.lookup("sap.com/MyEJBEar/HelloBean");

com.wipro.hello.HelloHome home=

(com.wipro.hello.HelloHome)javax.rmi.PortableRemoteObject

.narrow(obj,com.wipro.hello.HelloHome.class);

com.wipro.hello.Hello h=home.create();

out.println(h.sayHello());

}

catch(Exception e)

{

out.println("Error "+e);

}

%>

and finally edited the portalapp.xml file(found in the path MyEJBPar\dist\PORTAL-INF.

and add the following tag:

<component name="MyJSP">

<component-config>

<property name="ComponentType" value="jspnative">

</property>

<property name="JSP" value="jsp/MyJSP.jsp">

</property>

</component-config>

<component-profile/>

</component>

Then I deployed the par file and when I created a iView for my MyJSP component , it is able to access my MyEJB component and return the output.

Hope this will solve your problem.

Thanks

Hari

former_member394902
Contributor
0 Kudos

Hi Vasu,

have you created a EJB Local reference in web.xml file ??

Former Member
0 Kudos

Hi Vasu,

could u pls explain more abt your problem.. may be with some code...

Rgds,

Raj