-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: tutorial part 3 error
PostPosted: Fri Jul 24, 2009 10:03 am 
Newbie

Joined: Fri Jul 24, 2009 9:50 am
Posts: 1
hi i'm a newbie in hibernate and i have a error in hibernate tutorial from documentation in part 3, where develop the interface via java servlets.
this is the error-SEVERE: Servlet.service() for servlet hello threw exception java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

what does it mean?
this is my code
Code:


import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;




public class EventManagerServlet extends HttpServlet {
   
   
    public void service(HttpServletRequest request,
             HttpServletResponse response)
                     throws ServletException, IOException {
       SimpleDateFormat dateFormatter = new SimpleDateFormat( "dd.MM.yyyy" );
       try {
//        Begin unit of work
       HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
//        Process request and render page...
      
//       Write HTML header
       PrintWriter out = response.getWriter();
       out.println("<html><head><title>Event Manager</title></head><body>");
//        Handle action
       if ( "store".equals(request.getParameter("action")) ) {
       String eventTitle = request.getParameter("eventTitle");
       String eventDate = request.getParameter("eventDate");
       if ( "".equals(eventTitle) || "".equals(eventDate) ) {
       out.println("<b><i>Please enter event title and date.</i></b>");
       }
       else {
       createAndStoreEvent(eventTitle, dateFormatter.parse(eventDate));
       out.println("<b><i>Added event.</i></b>");
       }
       }
//        Print page
       printEventForm(out);
       listEvents(out, dateFormatter);
//        Write HTML footer
       out.println("</body></html>");
       out.flush();
       out.close();
      
//        End unit of work
       HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
       }
       catch (Exception ex) {
       HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().rollback();
       if ( ServletException.class.isInstance( ex ) ) {
       throw ( ServletException ) ex;
       }
       else {
       throw new ServletException( ex );
       }
       }/**/
    }
   
   private void printEventForm(PrintWriter out) {
      out.println("<h2>Add new event:</h2>");
      out.println("<form>");
      out.println("Title: <input name='eventTitle' length='50'/><br/>");
      out.println("Date (e.g. 24.12.2009): <input name='eventDate' length='10'/><br/>");
      out.println("<input type='submit' name='action' value='store'/>");
      out.println("</form>");
      }
   
   private void listEvents(PrintWriter out, SimpleDateFormat dateFormatter) {
      List result = HibernateUtil.getSessionFactory()
      .getCurrentSession().createCriteria(Event.class).list();
      if (result.size() > 0) {
      out.println("<h2>Events in database:</h2>");
      out.println("<table border='1'>");
      out.println("<tr>");
      out.println("<th>Event title</th>");
      out.println("<th>Event date</th>");
      out.println("</tr>");
      Iterator it = result.iterator();
      while (it.hasNext()) {
      Event event = (Event) it.next();
      out.println("<tr>");
      out.println("<td>" + event.getTitle() + "</td>");
      out.println("<td>" + dateFormatter.format(event.getDate()) + "</td>");
      out.println("</tr>");
      }
      out.println("</table>");
      }
   }
   
   protected void createAndStoreEvent(String title, Date theDate) {
      Event theEvent = new Event();
      theEvent.setTitle(title);
      theEvent.setDate(theDate);
      HibernateUtil.getSessionFactory()
      .getCurrentSession().save(theEvent);
   }
   
   protected void doGet(
   HttpServletRequest request,
   HttpServletResponse response) throws ServletException, IOException {
   SimpleDateFormat dateFormatter = new SimpleDateFormat( "dd.MM.yyyy" );
   try {
//    Begin unit of work
      HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
      //    Process request and render page...
      
//       Write HTML header
      PrintWriter out = response.getWriter();
      out.println("<html><head><title>Event Manager</title></head><body>");
//       Handle actions
      if ( "store".equals(request.getParameter("action")) ) {
      String eventTitle = request.getParameter("eventTitle");
      String eventDate = request.getParameter("eventDate");
      if ( "".equals(eventTitle) || "".equals(eventDate) ) {
      out.println("<b><i>Please enter event title and date.</i></b>");
      }
      else {
      createAndStoreEvent(eventTitle, dateFormatter.parse(eventDate));
      out.println("<b><i>Added event.</i></b>");
      
      }
      }
//       Print page
      printEventForm(out);
      listEvents(out, dateFormatter);
//       Write HTML footer
      out.println("</body></html>");
      out.flush();
      out.close();
      
      //    End unit of work
      HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
      }
      catch (Exception ex) {
         HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().rollback();
      if ( ServletException.class.isInstance( ex ) ) {
         throw ( ServletException ) ex;
      }
      else {
         throw new ServletException( ex );
         }
      }
   }
   
   
}




i use Eclipse 3.2 tomcat 6
can anybody help me?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.