salve a tutti...
mi stò avvicinado (tutto di un botto - lo so che si deve fare un passo alla volta, ma per motivi universitari devo cercare di fare tutto insieme) al framework "Hibernate" e per prendere familiarità ho eseguito l'esempio presente sull'articolo "Introduzione ad Hibernate" e ho riportato il codice della Classe usata per testare la persistenza del javabean Persona nella seguente servlet:
ho creato una web application con eclipse che si presenta così:codice:package test; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletResponse; import javax.servlet.RequestDispatcher; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import beans.Persona; public class PersonaUnitTest extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { /* (non-Java-doc) * @see javax.servlet.http.HttpServlet#HttpServlet() */ public PersonaUnitTest() { super(); } /* (non-Java-doc) * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //System.out.println("Persona Unit Test"); // Recupero la sessione: attenzione, questa operazione // può essere gestita come un Singleton lungo tutta l'applicazione org.hibernate.Session session = new Configuration().configure().buildSessionFactory().getCurrentSession(); //Creo una nuova persona Persona p = new Persona(); p.setNome("Pasquale"); p.setNome("Congiustì"); p.setEmail("p.congiusti@html.it"); //Utilizziamo un modello transazionale dichiarativo session.beginTransaction(); //Chiedo al middleware di salvare questo oggetto nel database session.save(p); //fine della transazione: salviamo tramite commit() session.getTransaction().commit(); //System.out.println("I dati inseriti sono:"); //System.out.println("Nome: " + p.getNome()); //System.out.println("Cognome: " + p.getCognome()); //System.out.println("E-Mail: " + p.getEmail()); RequestDispatcher dispatcher; dispatcher = getServletContext().getRequestDispatcher("/ShowUser.jsp"); dispatcher.forward(request,response); } /* (non-Java-doc) * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); } }
c'è una pagina html (index.html) che richiama tramite un form la servlet "PersonaUnitTest" che dopo aver effettuato l'inserimento ne db fa un forward alla pagina "ShowUser.jsp" che non fa altro che scrive un messaggio di conferma
il punto è che quando eseguo l'application mi esce questo errore:
cosa può essere?...un problema con Hibernate o con la Servlet?codice:exception javax.servlet.ServletException: Servlet execution threw an exception root cause java.lang.NoClassDefFoundError: org/dom4j/DocumentException test.PersonaUnitTest.doGet(PersonaUnitTest.java:44) javax.servlet.http.HttpServlet.service(HttpServlet.java:690) javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
scusate la domanda che forse è stupida ma sono i mie primi "esperimenti" sia con le Servlet che con hibrnate
un infinito grazie a chi mi rispondera!!!!
![]()
![]()
![]()

Rispondi quotando