LeanMoreTryMore
asked on
JSP query data which is invoked EJB method - EJB applicaiton works only jsp page
Anyone who please give me some idea how to create a jsp page which is invoked the viewActiveServiceRequest() method
from the ejb application
I have completed the EJB application and create a sample web page to insert the record via servlet in which calls the EJB session process to insert the record to the database. IT WORKS OK. the record has been saved to the database.
Now i want to write a JSP page which calls the viewActiveServiceRequest methods.
public interface ServiceRequestProcessor extends EJBObject {
public ServiceRequestModel[] viewActiveServiceRequest()
throws RemoteException, ServiceRequestException;
========================== ========== ========== ========== ========== =
please help.
The ejb application works ok just need to know how to displays ALL records
Bean Class
/**
* Business Method.
*/
public ServiceRequestModel[] viewActiveServiceRequest()
throws ServiceRequestException {
ArrayList bookings = new ArrayList();
try {
Collection active = srHome.findByStatus(Consta nts.STATUS _ACTIVE);
for (Iterator iterator = active.iterator(); iterator.hasNext();) {
bookings.add(
getSrModel((ServiceRequest Local) iterator.next()));
}
} catch (FinderException e) {
e.printStackTrace();
throw new ServiceRequestException(e. getMessage ());
}
ServiceRequestModel[] result = new ServiceRequestModel[bookin gs.size()] ;
bookings.toArray(result);
return result;
}
from the ejb application
I have completed the EJB application and create a sample web page to insert the record via servlet in which calls the EJB session process to insert the record to the database. IT WORKS OK. the record has been saved to the database.
Now i want to write a JSP page which calls the viewActiveServiceRequest methods.
public interface ServiceRequestProcessor extends EJBObject {
public ServiceRequestModel[] viewActiveServiceRequest()
throws RemoteException, ServiceRequestException;
==========================
please help.
The ejb application works ok just need to know how to displays ALL records
Bean Class
/**
* Business Method.
*/
public ServiceRequestModel[] viewActiveServiceRequest()
throws ServiceRequestException {
ArrayList bookings = new ArrayList();
try {
Collection active = srHome.findByStatus(Consta
for (Iterator iterator = active.iterator(); iterator.hasNext();) {
bookings.add(
getSrModel((ServiceRequest
}
} catch (FinderException e) {
e.printStackTrace();
throw new ServiceRequestException(e.
}
ServiceRequestModel[] result = new ServiceRequestModel[bookin
bookings.toArray(result);
return result;
}
ASKER
i'm not using struts not because i dont want to..its because of SAP netweaver is not totally support struts as they are still using the jkd 14.
How about Servlet?
I never saw any application that calls EJB directly from EJB.
I never saw any application that calls EJB directly from EJB.
ASKER
JSP
<%@ page import="javax.naming.*, javax.rmi.PortableRemoteOb ject, com.u8.servicerequest.SrTy peProcesso rLocal, com.u8.servicerequest.SrTy peProcesso rLocalHome , com.u8.servicerequest.util .SrTypeMod el" %>
<%!
//declare a "global" reference to an instance of the home interface of the session bean
SrTypeProcessorLocal srTypeHome=null;
public void jspInit() throws ServletException {
//obtain an instance of the home interface
try {
Context ctx = new InitialContext();
Object ref = ctx.lookup("java:comp/env/ ejb/SrType ProcessorB ean");
srTypeHome = (SrTypeProcessorLocal)Port ableRemote Object.nar row(ref,Sr TypeProces sorLocal.c lass);
} catch (CreateException e) {
e.printStackTrace();
throw new ServletException(e.toStrin g());
} catch (NamingException e) {
e.printStackTrace();
throw new ServletException(e.toStrin g());
}
}
%>
<%
//instantiate the session bean
SrTypeProcessorLocal srType = srTypeHome.create();
//invoke the remote methods
%>
PLEASE ADVISE WHAT WRONG
<%@ page import="javax.naming.*, javax.rmi.PortableRemoteOb
<%!
//declare a "global" reference to an instance of the home interface of the session bean
SrTypeProcessorLocal srTypeHome=null;
public void jspInit() throws ServletException {
//obtain an instance of the home interface
try {
Context ctx = new InitialContext();
Object ref = ctx.lookup("java:comp/env/
srTypeHome = (SrTypeProcessorLocal)Port
} catch (CreateException e) {
e.printStackTrace();
throw new ServletException(e.toStrin
} catch (NamingException e) {
e.printStackTrace();
throw new ServletException(e.toStrin
}
}
%>
<%
//instantiate the session bean
SrTypeProcessorLocal srType = srTypeHome.create();
//invoke the remote methods
%>
PLEASE ADVISE WHAT WRONG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In my opinion, you should have one more layer (Servlet / Struts) between your JSP and EJB. So use your Servlet / Struts to get this data and send it to request context so that JSP can retrieve it from request. I do not think that it is a normal and suggested way to directly invoked EJB from JSP.
Similarly, when you insert the data to EJB, your Servlet / Struts will validate the data first then call the EJB.
Hope that helps.
David