Solved

JSP query data which is invoked EJB method - EJB applicaiton works only jsp page

Posted on 2006-11-23
5
220 Views
Last Modified: 2010-04-01
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(Constants.STATUS_ACTIVE);
          for (Iterator iterator = active.iterator(); iterator.hasNext();) {
               bookings.add(
               getSrModel((ServiceRequestLocal) iterator.next()));
            }
       } catch (FinderException e) {
              e.printStackTrace();
              throw new ServiceRequestException(e.getMessage());
            }

            ServiceRequestModel[] result = new ServiceRequestModel[bookings.size()];
            bookings.toArray(result);                  
            return result;
      }
0
Comment
Question by:LeanMoreTryMore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:suprapto45
ID: 18005866
Hi,

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
0
 

Author Comment

by:LeanMoreTryMore
ID: 18015227
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.

0
 
LVL 16

Expert Comment

by:suprapto45
ID: 18017262
How about Servlet?

I never saw any application that calls EJB directly from EJB.
0
 

Author Comment

by:LeanMoreTryMore
ID: 18050465
JSP

<%@ page import="javax.naming.*, javax.rmi.PortableRemoteObject, com.u8.servicerequest.SrTypeProcessorLocal, com.u8.servicerequest.SrTypeProcessorLocalHome, com.u8.servicerequest.util.SrTypeModel" %>

<%!
 //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/SrTypeProcessorBean");
       srTypeHome = (SrTypeProcessorLocal)PortableRemoteObject.narrow(ref,SrTypeProcessorLocal.class);
   } catch (CreateException e) {
         e.printStackTrace();
         throw new ServletException(e.toString());
   } catch (NamingException e) {
         e.printStackTrace();
         throw new ServletException(e.toString());
   }
 }
%>

<%
 //instantiate the session bean
  SrTypeProcessorLocal srType = srTypeHome.create();
 //invoke the remote methods
%>

PLEASE ADVISE WHAT WRONG
0
 
LVL 10

Accepted Solution

by:
mbvvsatish earned 500 total points
ID: 18120534
the jspInit() method may not be invoked, it is purely dependent on the container.
some containers have init method as _jspInit().

as you know when the first request comes to jsp, it is complied and converted into a servlet. so check the converted servlet java source file available in your server.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
best tutorial on log4j and logging for servlets/jsp codes 1 65
spring example non maven 4 100
Java Script nested call 3 89
designing in object programming 12 109
Original post  on Monitis Blog. Web performance monitoring is broken into two camps: passive and active. Passive monitoring is defined as looking at real-world historical performance by monitoring actual log-ins, site hits, clicks, requests for…
This article was initially published on Monitis Blog, you can read it here . When it comes to deciding which approach to website performance monitoring is best for your business, unfortunately, like so many options in life . . . it depends. In t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question