Results 1 to 2 of 2
  1. #1
    mihael is offline Member
    Join Date
    Dec 2008
    Posts
    4
    Rep Power
    0

    Default stateless session bean error

    I have to create stateless session bean with 3 methods and then create a servlet which remotely calls all three methods in that session bean. I have 4 files created-index.jsp under web-inf, and 3 files under mlpackage that i created but not able to execute. can you please help what is worong with the code for this WebApplication I created?Thanks, friend

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <h2>Hello JSPWorld!</h2>
    <a href="NewServlet">Click here to call the EJB component</a>
    <p>The Date is <%= new java.util.Date() %>
    </body>
    </html>


    package mlpackage;

    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.ejb.EJB;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    /**
    *
    * @author mihael
    */
    public class NewServlet extends HttpServlet {

    /**
    * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    */

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
    //TODO output your page here
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Servlet NewServlet</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>Servlet NewServlet at " + request.getContextPath () + "</h1>");
    out.println("</body>");
    out.println("</html>");

    } finally {
    out.close();
    }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
    * Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    @EJB
    private NewServletsessionRemote testNewServlet;

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
    System.out.println(testNewServlet.getMessage());
    }

    }
    /**
    * Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    }

    /**
    * Returns a short description of the servlet.
    */
    public String getServletInfo() {
    return "Short description";
    }// </editor-fold>

    }

    package mlpackage;



    import javax.ejb.Stateless;


    /**
    *
    * @author mihael
    */
    @Stateless
    public class NewServletsessionBean implements NewServletsessionRemote
    {
    private String name;
    private String socialsecurity;
    private String birthcity;
    private int hours;

    public String getMessage()
    {
    return "Hello MLsessionBean";
    }
    public String getname()
    {
    return name;
    }
    public void setsocialsecurity( String ss )
    {
    socialsecurity = ss;
    }

    // return social security
    public String getsocialsecurity()
    {
    return socialsecurity;
    }

    public void setbirthcity( String bc )
    {
    birthcity = bc;
    }

    public String getbirthcity()
    {
    return birthcity;
    }

    public String bc()
    {
    //throw new UnsupportedOperationException("Not supported yet.");
    return birthcity;
    }

    public void ML(String name, String socialsecurity, int hours) {
    throw new UnsupportedOperationException("Not supported yet.");
    }

    public void businessMethod(String person) {
    throw new UnsupportedOperationException("Not supported yet.");
    }


    // Add business logic below. (Right-click in editor and choose
    // "EJB Methods > Add Business Method" or "Web Service > Add Operation")

    }

    package mlpackage;

    import javax.ejb.Remote;


    /**
    *
    * @author mihael
    */
    @Remote
    public interface NewServletsessionRemote
    {
    public void ML(String name, String socialsecurity, int hours);
    public void businessMethod(String person);
    public java.lang.String getMessage();
    public java.lang.String getname();
    public void setsocialsecurity(java.lang.String ss);

    }

  2. #2
    ishtiak is offline Member
    Join Date
    Jan 2009
    Posts
    1
    Rep Power
    0

    Default

    Hi,

    I think, u may have to do proper lookup code with context properties.

    More at

    interview-questions-tips-forum.net

    Thanks.

Similar Threads

  1. stateless session bean with methods
    By mihael in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 01-15-2009, 08:55 PM
  2. UREGENT-accessing session bean ok but entity bean
    By parimal in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 08-28-2008, 01:34 PM
  3. [SOLVED] Invoking a Stateful Session Bean as Stateless
    By JThangiah in forum Enterprise JavaBeans (EJB)
    Replies: 3
    Last Post: 07-17-2008, 09:35 AM
  4. Stateful Session Bean
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-29-2007, 12:39 PM
  5. Stateless Session Bean
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-29-2007, 12:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •