java.lang.NoSuchMethodError

Discussions

EJB programming & troubleshooting: java.lang.NoSuchMethodError

  1. java.lang.NoSuchMethodError (5 messages)

    I have a servlet, a jsp, an EJB and a java bean. The servlet get user's request and forward results to jsp. The jsp uses java bean which again access an EJB. Everything was fine before I add "session.setAttribute("allBooks", v)", v is a vector which basically stores a bunch of books. Whenever I added "session.setAttribute("allBooks", v)", I got the following error:

    ------------------------------------------------------------
    root cause

    java.lang.NoSuchMethodError:

    javax.servlet.http.HttpSessionBindingEvent.(Ljavax/servlet/http/HttpSession;Ljava/lang/String;Ljava/lang/Object;)V

    at
    org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:1182)

    at
    org.apache.catalina.session.StandardSessionFacade.setAttribute(StandardSessionFacade.java:191)

    at
    org.apache.catalina.session.StandardSessionFacade.setAttribute(StandardSessionFacade.java:191)

    at BookUpdateServlet.doPost(BookUpdateServlet.java:123)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)

    at
    org.apache.catalina.core.ApplicationFilterChain.access$0(ApplicationFilterChain.java:197)

    at
    org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:176)

    at java.security.AccessController.doPrivileged(Native Method)
    at
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:172)

    at
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)

    at
    org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

    at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

    at
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)

    at
    org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

    at
    org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)

    at
    org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)

    at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

    at
    org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)

    at
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)

    at
    org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

    at
    org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)

    at
    org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)

    at
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)

    at
    org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)

    at
    org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:368)

    at
    org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)

    at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

    at
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)

    at
    org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

    at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

    at
    org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)

    at
    org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)

    at java.lang.Thread.run(Thread.java:536)

    ------------------------------------------------------------

    When I was taking a J2EE training class in a different machine, I was using the same piece of code and I had no such problem!
    I think the problem is the classpath, which makes the server not be able to understand "session.setAttribute()" method. it also can not understand:
    RequestDispatcher dispatch = getServletContext().getRequestDispatcher("/BookUpdateJSP.jsp");
    dispatch.forward(request, response);

    Maybe the classpath of the j2ee server in my training class is different from that of the j2ee server that I am using now? What kind of classpath should I add to?
    Now the classpath on my server is:

    Please help!

    Thanks a lot.

    Jingzhi Liu



    Threaded Messages (5)

  2. java.lang.NoSuchMethodError[ Go to top ]

    I forgot to mention that I am using J2EE Reference Implementation (RI).
  3. java.lang.NoSuchMethodError[ Go to top ]

    I also notice that whenever I use JSP, I will get an error.

    What could be the problem?

    Please help!
  4. java.lang.NoSuchMethodError[ Go to top ]

    dude.. make sure you have the same version of JAR file (your application) in your ejb container and the servlet/jsp container -- catalina.

    if you have session binded object -- instances of the class from the old jar file, you may have to restart the container..

    i suggest to restart both container..
  5. java.lang.NoSuchMethodError[ Go to top ]

    Yes, I did restart the server and tried many times. Is there a bug in the J2EE RI?

    Here is the detailed information about my problem:
    The following is my code:
    **********************************************************
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {

    BookUpdateJavaBean bean = new BookUpdateJavaBean();

    Integer isbn = new Integer(request.getParameter("ISBN"));
    String title = request.getParameter("title");
    String author = request.getParameter("author");
    double price = Double.parseDouble(request.getParameter("price"));

    bean.setISBN(isbn);
    bean.setTitle(title);
    bean.setAuthor(author);
    bean.setPrice(price);

    //insert books into the catalog
    bean.insertData();

    //get all the books from the catalog
    Vector v = bean.getAllBooks();

    HttpSession session = request.getSession(true);
    session.setAttribute("allBooks", v);

    RequestDispatcher dispatch = getServletContext().getRequestDispatcher("/BookUpdateJSP.jsp");
    dispatch.forward(request, response);

    /*Vector v = bean.getAllBooks();
    int size = v.size();
    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();

    out.println("<html>");
    out.println("<head>");
    out.println("<title>List of books in the catalog!</title>");
    out.println("</head>");
    out.println("<body>");

    out.println("<h3>There are now <font color=red>" + size + "</font> books in the catalog:</h3>");
    out.println("<table border=1>");
    out.println("<tr>");
    out.println("<td>ISBN</td>");
    out.println("<td>Title</td>");
    out.println("<td>Author</td>");
    out.println("<td>Price</td>");
    out.println("</tr>");
    for(int i = 0; i < size; i++){
    String array[] = (String[])v.elementAt(i);
    out.println("<tr>");
    out.println("<td>" + array[0] + "</td>");
    out.println("<td>" + array[1] + "</td>");
    out.println("<td>" + array[2] + "</td>");
    out.println("<td>" + array[3] + "</td>");
    out.println("</tr>");
    }
    out.println("</table>");
    out.println("</body>");
    out.println("</html>");

    out.close();*/

    //response.sendRedirect("/Book/BookUpdateJSP.jsp");
    }
    ************************************************************
    Notice that if I only use the Servlet (the commented code), it is working correctly which basically retrieves the books from the database and display the catalog on the screen! But you know that is kind of cumbersome if I write HTML in servlet, so that is why I want to use JSP, which means that I get data from the JavaBeans (which again access a method from an EJB), store in the vector, and then forward the result to the JSP for display (typical MVC pattern). the following shows the code that is not working:
    ***********************************************************
    HttpSession session = request.getSession(true);
    session.setAttribute("allBooks", v);

    RequestDispatcher dispatch = getServletContext().getRequestDispatcher("/BookUpdateJSP.jsp");
    dispatch.forward(request, response);
    ************************************************************
    Furthermore, I notice that whenever I use JSP in my J2EE RI, I will get error. But it works fine for Servlets only.

    Finally, I should mention that when I was taking an EJB training class, I use the same piece of code and same J2EE server (the RI), and it was working for the above problem code!

    I believe the server that I am using does not have a JSP engine, but it only has a old servlet engine! But both the J2EE server that I am using now and the J2EE server that I was using in my training class are the same version, which is j2sdkee1.3.1, the latest version!

    Could you please tell me the reason?

    Thanks a lot!

    Jingzhi
     

  6. java.lang.NoSuchMethodError[ Go to top ]

    mmm... i suggest you to go download jboss/tomcat bundle to test it out... i may probably take a couple minutes to setup the instance and configure your ejb deployment descriptor...

    http://www.jboss.org/

    sorry can't help...
    anyway..

    i found the path to the JSP file here is different:
    RequestDispatcher dispatch = getServletContext().getRequestDispatcher("/BookUpdateJSP.jsp");

    than

    //response.sendRedirect("/Book/BookUpdateJSP.jsp");

    did you get a 404 when you try to redirect to the JSP?

    also, when you do redirect from servlet to JSP,
    you don't really need to set the vector to session.
    try to put it into the request scrope.
    e.g.
       request.setAttribute("allbooks", v);

    and do proper retrieval update (request.getAttribute())
    in your jsp file..