Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: IMPLEMENTING A STATEFUL SESSION BEAN APPLICATION USING NETBEANS

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default IMPLEMENTING A STATEFUL SESSION BEAN APPLICATION USING NETBEANS

    I ask this question and add code samples because of the pressing need to be clear about how i used to know how ejb applications are implemented in the past i.e 5 years earlier using sun one appserver 1.4 and the way it is done now using netbeans IDE (latest series with glassfish server). I know earlier that to implement an ejb application, there would be an HOME interface with a method giving a reference to a the REMOTE interface as return type. The REMOTE interface declares the business methods that gets implemented by an implementation class which serves as the ejb class. I've observed that recent implementations of ejb apps using netbeans seem to have left off the notion of HOME interface. My first question his:

    (1) Why is there no longer a reference to the HOME interface? In short what has changed?
    In a recent J2EE tutorial i came across, when it came to stage of packaging the ejb components, there was this mention of
    packaging a Cart interface , CartHome interface and CartBean class. I looked through the material, i could not see where the
    CartHome interface was implemented.
    (2) My second question is even after i've implemented the ejb components correctly. How do i call the same correctly in a JSP
    page?

    The code samples i supply here were implemented in sun one appserver years back. Now i'm using it as practice material
    to be acquainted better with ejb technologies and to know how i can implement it using netbeans IDE. At the moment my
    netbeans IDE version is 7.4. Another thing is that i'm interested in the stateful session bean applications. There seem to
    be no implementing of it even in netbeans ejb tutorials. The emphasis is mostly on stateless session beans...
    HERE ARE THE CODE SAMPLES: CODE LINES THAT GAVE NO ISSUES A LEFT OUT, COMMENT LINES ARE SHOWN

    STATEFUL SESSION BEAN HOME INTERFACE:

    package University;
    import java.io.Serializable;
    import java.rmi.RemoteException;
    import javax.ejb.CreateException;
    import javax.ejb.EJBHome;

    public interface CourseHome extends EJBHome
    {
    Course create(String studentName, String rollNo) throws RemoteException, CreateException;
    }

    STATEFUL SESSION BEAN REMOTE INTERFACE

    package University;
    import java.util.*;
    import javax.ejb.EJBObject;
    import java.rmi.RemoteException;

    public interface Course extends EJBObject
    {
    public String addCourse(String cname) throws RemoteException;
    public String removeCourse(String cname) throws RemoteException;
    public Vector getSelectedCourse() throws RemoteException;
    }

    STATEFUL SESSION BEAN CLASS

    public class CourseBean implements SessionBean
    {
    String studentName;
    String studentRollNo;
    Vector selectedCourse;
    public void ejbCreate(String StudentName, String RollNo) throws CreateException
    {
    if(StudentName == null)
    {
    throw new CreateException("Null person not allowed.");
    }
    else
    {
    studentName = StudentName;
    }
    selectedCourse = new Vector();
    }
    public String addCourse(String cname)
    {
    if(Cname == null)
    {

    return "";
    }
    try
    {
    if(!selectedCourse.isEmpty())
    {
    Enumeration enumer = selectedCourse.elements();
    String title="";
    while(enumer.hasMoreElements())
    {
    //the remaining logic goes on...
    }
    }
    else
    {
    ..........
    }
    }
    public String removeCourse(String Cname)
    {

    //code logic goes here...
    }
    public Vector getSelectedCourse()
    {
    return selectedCourse;
    }
    public CourseBean() {}
    public void ejbRemove() {}
    public void ejbActivate() {}
    public void setSessionContext(SessionContext sc) {}

    ALL THIS CODE I WOULD HAVE WANTED TO IMPLEMENT IN MY VERSION OF NETBEANS. BUT IN THE SPIRIT OF MY
    OBSERVATIONS WITH A RECENT IDE LIKE NETBEANS, I ONLY IMPLEMENTED THE REMOTE INTERFACE AND THE
    BEAN CLASS WITH NO IMPLEMENTING OF EJBObject and SessionBean. I BELIEVE THE AREA OF CONTENTION [/SIZE]IS IN THE CourseCart.jsp page where the ejb will be invoked after
    a user has supplied the a student name and roll number in form text fields. I will supply only the JSP SCRIPLETS of the
    page as implemented in page at the time...

    initializing code...before the starting HTML tag

    <%!
    private Course course = null;
    CourseHome home = null;
    public void jspInit()
    {
    //to locate the stateful session bean
    try
    {
    InitialContext ic = new InitialContext();
    Object objRef = ic.lookup("java:comp/env/ejb/Univ");
    home =(CourseHome)PortableRemoteObject.narrow(objRef, CourseHome.class));
    }
    catch(Exception ex)
    {}
    }
    %>
    //Another area to note...inside the form tag of CourseCart.jsp
    <form method="get" name="f1">
    <%
    String stdname = request.getParameter("stdname");
    String stdrollno = request.getParameter("stdrollno");
    if(stdname != null && stdname.length() > 0)
    {
    if(stdrollno != null && stdrollno.length() > 0)
    {
    course = home.create(stdname, stdrollno);
    }
    }
    %>

    I tried implementing this code using my version of netbeans but i kept receiving 500 internal
    source code error giving me null pointer exception.

    I'll appreciate anyone that can be of assistance in giving clear and concise answers to the
    questions given earlier:
    (1) How can i implement this stateful session bean app in recent NETBEAN IDE
    (2) Why does recent NETBEAN IDE version have no automatic support for
    EJBObject, SessionBean and Home interface. What has changed and why?
    (3) What is the correct way to invoke a stateful session bean from a JSP page
    especially a stateful session bean class that supplies implementation code
    for a lifecycle method like ejbCreate() ?


    Olakunle Oni


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,571
    Thanks
    49
    Thanked 2,232 Times in 2,204 Posts

    Default Re: IMPLEMENTING A STATEFUL SESSION BEAN APPLICATION USING NETBEANS

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Implementing Session Tracking
    By Anitush in forum Java Theory & Questions
    Replies: 1
    Last Post: September 27th, 2013, 11:43 AM
  2. Replies: 0
    Last Post: April 5th, 2013, 07:16 PM
  3. Replies: 1
    Last Post: September 15th, 2011, 07:50 AM
  4. [SOLVED] What do I need to do to use a bean in Netbeans 7 apart from defining it?
    By Lord Voldemort in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: July 31st, 2011, 12:29 AM
  5. Replies: 0
    Last Post: December 3rd, 2009, 03:43 PM