Bon soir à tous et à toutes
je débute avec hibernate, et je rencontre un grand pb lors de la connection à la base de donnée MySQL avec le servelet. J'utilise hibernate2 et voici le code de ma servlet:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import com.hibernate.dao.*;
 
import com.hibernate.dao.base.BaseUtilisateurDAO;
 
import com.hibernate.service.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator; 
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
 
/**
 * Servlet implementation class Application
 * @param <ServletConfig>
 */
public class Application extends HttpServlet  {
	 private static final long serialVersionUID = 1L;
	 private ServletConfig config;
	 Service service ;
	 BaseUtilisateurDAO dao = null;
	public Application() {
		super();
	}   	
 
 
	public void init()
	    throws ServletException{
			ServletConfig config = getServletConfig();
 
			try {
				dao.init();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			service.setDao(dao);
	     }
 
 
	public void doGet(HttpServletRequest request, HttpServletResponse response)
	 throws IOException, ServletException {
		try {
			Session ses=HibernateUtil.currentSession();
 
			Transaction tx =ses.beginTransaction();
 
			doListPersonne(request, response,ses);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
 
	private void doListPersonne(HttpServletRequest request,
			 HttpServletResponse response , Session s) throws ServletException, IOException, HibernateException {
 
 
		try{Iterator<Utilisateur> it=service.getAll(s);
		PrintWriter out =response.getWriter();
		out.print("<table  border=\"1\">");
		while(it.hasNext()){
			Utilisateur e2 =(Utilisateur)it.next();
			out.print("<tr><td>"+ e2.getNom()+"</td>"+"<td>"+ e2.getAge()+"</td></tr>" );
	}
		out.print("</table>");
		}catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
 
 
	public void doPost(HttpServletRequest request, HttpServletResponse response)
	 throws IOException, ServletException {
	 // on passe la main au GET
  }
	}
et ceci est la trace de l'exécution de la servlet:
exception

javax.servlet.ServletException: "Servlet.init()" pour la servlet Application a généré une exception
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
java.lang.Thread.run(Unknown Source)


cause mère

java.lang.NullPointerException
Application.init(Application.java:58)
javax.servlet.GenericServlet.init(GenericServlet.java:211)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
java.lang.Thread.run(Unknown Source)

S'il vous plait aidez moi je suis complétement bloquée et ça fait longtemp que je cherche mais en vain
Je serais trés reconnaissante
Salem