PROBLEMA CON HIBERNATE-POSTGRESQL-TOMCAT IL FORM CHE HO CREATO USERNAME E PASSWORD DOVREBBE CONTROLLARE SE ESISTE L'UTENTE IN DB ATTRAVERSO UNA SERVLET E RESTITUIRE UNA PAGINA HTML DI RISPOSTA MA ... FINISCE TUTTO IN UNA TERRIBILE ECCEZIONE DA CUI NON RIESCO PROPRIO A USCIRMENE HO INSTALLATO TANTI JAR MA NIENTE DA FARE.
vi posto l'eccezione e le classi
type Exception report
message Servlet execution threw an exception
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet execution threw an exception
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cfg.Configuration
com.azienda.progettoCorso.dao.DaoHibernate.buildSessionFactory(DaoHibernate.java:31)
com.azienda.progettoCorso.dao.DaoHibernate.<init>(DaoHibernate.java:38)
com.azienda.esempiCorso.sessione15.LoginServlet.doPost(LoginServlet.java:34)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>Corso</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>com.azienda.esempiCorso.sessione15.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>com.azienda.esempiCorso.sessione15.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
---------------------------------------------------------------------------
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Login</title>
</head>
<body>
<div align="center" style="padding-top: 150px">
<form action="/Corso/login" method="post">
<table border="0" width="300px" height="100px" cellpadding="0" style="background-color:silver">
<tr>
<td align="right">
Username
</td>
<td align="left">
<input type="text" name="userName">
</td>
</tr>
<tr>
<td align="right">
password
</td>
<td>
<input type="password" name="password">
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="Login">
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
--------------------------------------------------------------
package com.azienda.esempiCorso.sessione15;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.azienda.progettoCorso.dao.DaoHibernate;
import com.azienda.progettoCorso.dao.DaoInterface;
import com.azienda.progettoCorso.model.Utente;
public class LoginServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
{
doPost(request,response);
}
@Override
protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
{
String userName = request.getParameter("userName");
String password = request.getParameter("password");
if ( userName != null && !userName.isEmpty() && password != null && !password.isEmpty() )
{
Utente utente = new Utente();
utente.setUserName(userName);
utente.setPassword(password);
DaoInterface dao = new DaoHibernate();
try
{
Utente utenteFromDb = dao.retrieveById(utente.getId(),true);
if ( utenteFromDb != null && utenteFromDb.getPassword().equals(password) )
{
request.getSession().setAttribute("userLogged","YES");
String requestUrl = (String) request.getSession().getAttribute("requestUrl");
if ( requestUrl != null && !requestUrl.isEmpty() )
{
request.getSession().removeAttribute("requestUrl");
request.getRequestDispatcher(requestUrl).forward(request,response);
}
else
{
request.getRequestDispatcher("/html/loginOk.html").forward(request,response);
}
}
else
{
request.getRequestDispatcher("/html/loginError.html").forward(request,response);
}
}
catch ( Exception ex )
{
ex.printStackTrace();
request.getRequestDispatcher("/html/loginError.html").forward(request,response);
}
finally
{
((DaoHibernate) dao).getSession().getSessionFactory().close();
}
}
else
{
request.getRequestDispatcher("/html/login.html").forward(request,response);
}
}
}
---------------------------------------------------------------
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0 dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost:5432/corso</property>
<property name="connection.username">corso</property>
<property name="connection.password">corso</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<mapping resource="com/azienda/progettoCorso/model/hbm/Materia.hbm.xml"/>
<mapping resource="com/azienda/progettoCorso/model/hbm/Aula.hbm.xml"/>
<mapping resource="com/azienda/progettoCorso/model/hbm/Sede.hbm.xml"/>
<mapping resource="com/azienda/progettoCorso/model/hbm/Soggetto.hbm.xml"/>
<mapping resource="com/azienda/progettoCorso/model/hbm/Corso.hbm.xml"/>
<mapping resource="com/azienda/progettoCorso/model/hbm/Utente.hbm.xml"/>
</session-factory>
</hibernate-configuration>
------------------------------------------------------------------
librerie jar tutte le necessarie.