erreur java.lang.ClassNotFoundException: org.hibernate.Session
Bonjour tout monde.
Je suis en train de faire une application hibernate , mysql et servlet j' ai un message d erreur le voici :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| java.lang.ClassNotFoundException: org.hibernate.Session
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at com.demo.controlleur.ServletUser.doPost(ServletUser.java:36)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619) |
Fichier de configuration hibernate :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/demo</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.search.autoregister_listeners">false</property>
<mapping class="com.demo.bean.Person" />
<mapping class="com.demo.bean.User" />
</session-factory>
</hibernate-configuration> |
Classe Hibernateutil avec annotation :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| package com.demo.util;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
public class HibernateUtil {
private static SessionFactory sessionfactory;
static{
try{
sessionfactory = new AnnotationConfiguration().configure().buildSessionFactory();
}catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed. : " + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory(){
return sessionfactory;
}
} |
Classe userimpldao :
Code:
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
| package com.demo.dao.impl;
import java.util.ArrayList;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.demo.bean.User;
import com.demo.dao.Dao;
import com.demo.util.HibernateUtil;
public class UserImpldao implements Dao<User> {
@Override
public void add(User obj) {
try{
HibernateUtil h = new HibernateUtil();
Session session =h.getSessionFactory().openSession();
Transaction tx =session.beginTransaction();
session.saveOrUpdate(obj);
tx.commit();
}catch (Exception e) {
}
}
@Override
public ArrayList<User> findAll() {
// TODO Auto-generated method stub
return null;
}
@Override
public User findByid(long id) {
// TODO Auto-generated method stub
return null;
}
@Override
public void remove(User obj) {
// TODO Auto-generated method stub
}
@Override
public void update(User obj) {
// TODO Auto-generated method stub
}
} |
Classe servletuser :
Code:
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
| package com.demo.controlleur;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.demo.bean.User;
import com.demo.dao.impl.UserImpldao;
/**
* Servlet implementation class ServletUser
*/
public class ServletUser extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out =response.getWriter();
String login = request.getParameter("login");
String pasword = request.getParameter("pasword");
if(!login.isEmpty()&&!pasword.isEmpty()){
UserImpldao unuser = new UserImpldao();
User u = new User();
u.setUsername(login);
u.setPassword(pasword);
unuser.add(u);
}
else{
out.println("<b><i>Please enter event title and date.</i></b>");
}
}
} |
Code:
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
| <?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</head>
<body>
<form action="ServletUser" method="post">
<table border="1" cellpadding="3" cellspacing="0">
<tr>
<td>Login :</td>
<td><input type="text" name="login" value="" size=15></input></td>
</tr>
<tr>
<td>Password :</td>
<td><input type="password" name="pasword" value="" size=15></input></td>
</tr>
<tr>
<td colspan="="2" align="right"><input type="submit" name="Valider" value="Valider"/></td>
</tr>
</table>
</form>
</body>
</html> |
Merci pour votre aide.