我正在尝试通过Connexion.java连接到我的本地 webapp 。但是这个错误弄清楚了。请问我该如何解决?
java.lang.ClassNotFoundException: org.hibernate.HibernateException at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559) at com.bh.servlets.Connexion.doPost(Connexion.java:28) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:647) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:728)在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 在 org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter (SetCharacterEncodingFilter.java:108) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) 在 org.apache.catalina.core.StandardContextValve .invoke(StandardContextValve.java:123) 在 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) 在 org. org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) 中的 apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve. java:118) 在 org.apache.coyote.http11 的 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)。AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java: 312) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 在 java.lang.Thread.run(Unknown Source) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)在 java.lang.Thread.run(Unknown Source) 处运行(Unknown Source)在 java.lang.Thread.run(Unknown Source) 处运行(Unknown Source)
ConnexionForm.java
public final class ConnexionForm {
private static final String CHAMP_LOGIN = "login";
private static final String CHAMP_PASS = "mdp";
private String resultat;
private Map<String, String> erreurs = new HashMap<String, String>();
public String getResultat() {
return resultat;
}
public Map<String, String> getErreurs() {
return erreurs;
}
public User connecterUser( HttpServletRequest request ) {
/* Récupération des champs du formulaire */
String login = getValeurChamp( request, CHAMP_LOGIN );
String mdp = getValeurChamp( request, CHAMP_PASS );
User User = new User();
/* Validation du champ login. */
try {
validationChamps( login , mdp );
} catch ( Exception e ) {
setErreur( "champs", e.getMessage() );
}
User.setIdentifiant( login );
/* Initialisation du résultat global de la validation. */
if ( erreurs.isEmpty() ) {
resultat = "Succès de la connexion.";
} else {
resultat = "<br/>Le nom d'utilisateur ou le mot de passe saisi est incorrect. <br/><br/>Échec de la connexion.";
}
return User;
}
private void validationChamps( String login , String mdp) throws Exception {
if(find(login) != null && !mdp.matches(find(login).getMdp()))
throw new Exception( "Le nom d'utilisateur ou le mot de passe saisi est incorrect." );
}
public User find(String login) {
User u = null;
try {
Session s = HibernateUtils.getSession();
Transaction tx = s.beginTransaction();
Query query = s.createQuery("from User where id = :y");
query.setString("y", login);
u = (User) query.uniqueResult();
tx.commit();
} catch (HibernateException e) {
System.out.println(e.getMessage());
} finally {
// s.close();
}
return u;
}
/*
* Ajoute un message correspondant au champ spécifié à la map des erreurs.
*/
private void setErreur( String champ, String message ) {
erreurs.put( champ, message );
}
/*
* Méthode utilitaire qui retourne null si un champ est vide, et son contenu
* sinon.
*/
private static String getValeurChamp( HttpServletRequest request, String nomChamp ) {
String valeur = request.getParameter( nomChamp );
if ( valeur == null || valeur.trim().length() == 0 ) {
return null;
} else {
return valeur;
}
}
}
连接.java
public class Connexion extends HttpServlet {
public static final String ATT_USER = "user";
public static final String ATT_FORM = "form";
public static final String ATT_SESSION_USER = "sessionUtilisateur";
public static final String VUE = "/WEB-INF/connexion.jsp";
public static final String ACCUEIL = "/WEB-INF/accueil.jsp";
public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
/* Affichage de la page de connexion */
this.getServletContext().getRequestDispatcher( VUE ).forward( request, response );
}
public void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
ConnexionForm form = new ConnexionForm();
User user = form.connecterUser( request );
HttpSession session = request.getSession();
request.setAttribute( ATT_FORM, form );
request.setAttribute( ATT_USER, user );
if ( form.getErreurs().isEmpty() ) {
session.setAttribute( ATT_SESSION_USER, user );
response.sendRedirect( request.getContextPath() + "/accueil" );
} else {
session.setAttribute( ATT_SESSION_USER, null );
this.getServletContext().getRequestDispatcher( VUE ).forward( request, response );
}
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>Connexion</servlet-name>
<servlet-class>com.bh.servlets.Connexion</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Connexion</servlet-name>
<url-pattern>/connexion</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Deconnexion</servlet-name>
<servlet-class>com.bh.servlets.Deconnexion</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Deconnexion</servlet-name>
<url-pattern>/deconnexion</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Accueil</servlet-name>
<servlet-class>com.bh.servlets.Accueil</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Accueil</servlet-name>
<url-pattern>/accueil</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Operation</servlet-name>
<servlet-class>com.bh.servlets.Operation</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Operation</servlet-name>
<url-pattern>/afficheOperations</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Upload</servlet-name>
<servlet-class>com.bh.servlets.Upload</servlet-class>
<init-param>
<param-name>chemin</param-name>
<param-value>/fichiers/</param-value>
</init-param>
<multipart-config>
<location>E:/fichiers</location>
<max-file-size>485760</max-file-size>
<max-request-size>52428800</max-request-size>
<file-size-threshold>1048576</file-size-threshold>
</multipart-config>
</servlet>
<servlet-mapping>
<servlet-name>Upload</servlet-name>
<url-pattern>/upload</url-pattern>
</servlet-mapping>
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>ignore</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
注意:在 com.bh.servlets.Connexion.doPost(Connexion.java:28) = 在这个Connexion.java类中的 com.bh.servlets.Connexion.doPost(Connexion.java:14)
我没有使用弹簧