Hallo!
Bin neu hier, aber begeistert über die kompetenten Antworten der Mitglieder. Erstelle derzeit eine Projekt, wo ich JSP (z. B. login.jsp), Servlets (z. B. login.java) und Hibernate nutze. Zugriff auf die DB erfolgt über die Methode "doPost" in der Klasse login.java.
Hier wollte ich eine einfache Login-Abfrage erstellen und habe das Problem, dass anscheinend die Hibernate-Klassen (ClassNotFound Exception) nicht gefunden werden.
Nebenei: Zwar kann ich die ganze Applikation unter Eclipse als Java Application starten, aber sobald ich diese über den Tomcat auf dem Server deploye und auf der login.jsp-Seite Usernamen und Passwort eingebe kriege ich die Exception:
java.lang.ClassNotFoundException: org.hibernate.HibernateException
Vielleicht kann jemand helfen? :wein:
[FONT=-moz-fixed]08.01.2010 23:08:58 org.apache.catalina.core.StandardWrapperValve invoke
SCHWERWIEGEND: Servlet.service() for servlet login threw exception
java.lang.ClassNotFoundException: org.hibernate.HibernateException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at BL.login.doPost(login.java:35)
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:128)
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:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)
[/FONT]
Alles anzeigen
Anbei der Code des Servlets login.java
import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.swing.plaf.ListUI;
import main.java.org.hibernate.DB.Nachrichten;
import main.java.org.hibernate.DB.Rechte;
import main.java.org.hibernate.DB.User;
import Hibernate.NachrichtenHibernate;
import Hibernate.RechteHibernate;
import Hibernate.UserHibernate;
import Hibernate.UserHibernate;
import Tests.TestUser;
public class login extends HttpServlet
{
public static void main(String[] args)
{
// TestUser.currentUser("biroluser", "asdf");
//u = new UserHibernate();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
UserHibernate u = new UserHibernate();
User user = new User();
System.out.println("======");
List users = u.getAll();
u.commit();
System.out.println("======");
for (int i = 0; i < users.size(); i++)
{
user = (User) users.get(i);
if (user.getUsername().equals(request.getParameter("user")))
{
if (user.getPasswort().equals(request.getParameter("pass")))
{
System.out.println("User found, pass ok");
}
else
{
System.out.println("password false");
}
}
else
{
System.out.println("user not found");
}
}
response.setContentType("text/html");
}
Alles anzeigen
Wie an der Fehlerausgabe zu sehen ist in der login.java die Zeile 35
UserHibernate u = new UserHibernate();
nicht auffindbar oder so.
Code der UserHibernate.java Datei, die für das Hibernate verwendet wird.
package Hibernate;
import java.util.List;
import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import main.java.org.hibernate.DB.Rechte;
import main.java.org.hibernate.DB.User;
import main.java.org.hibernate.util.HibernateUtil;
import DAO.UserDAO;
public class UserHibernate implements UserDAO
{
@Override
public User get(int id) throws RuntimeException
{
User user = null;
try
{
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
user = (User) session.load(Rechte.class, id);
}
catch (HibernateException e)
{
throw new RuntimeException(e.getMessage());
}
finally
{
// HibernateSessionFactory.closeSession();
}
return user;
}
@Override
public void remove(User user) throws RuntimeException
{
try
{
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
session.delete(user);
}
catch (Exception e)
{
HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().rollback();
throw new RuntimeException(e.getMessage());
}
finally
{
// HibernateSessionFactory.closeSession();
}
}
@Override
public void save(User user) throws RuntimeException
{
try
{
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
session.saveOrUpdate(user);
}
catch (Exception e)
{
HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().rollback();
throw new RuntimeException(e.getMessage());
}
finally
{
// HibernateSessionFactory.closeSession();
}
}
@Override
public List<?> find(String where) throws RuntimeException
{
List list = null;
try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
list = session.createQuery("from " + User.class.getName() + " where " + where).list();
} catch (HibernateException e) {
throw new RuntimeException(e.getMessage());
} finally {
// HibernateSessionFactory.closeSession();
}
return list;
}
@Override
public List<?> getAll() throws RuntimeException
{
List list = null;
try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
list = session.createQuery("from " + User.class.getName()).list();
} catch (HibernateException e) {
// throw new RuntimeException(e.getMessage());
throw e;
} finally {
// HibernateSessionFactory.closeSession();
}
return list;
}
public void commit() throws RuntimeException
{
try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.getTransaction().commit();
} catch (HibernateException e) {
// throw new RuntimeException(e.getMessage());
throw e;
} finally {
// HibernateSessionFactory.closeSession();
}
}
}
Alles anzeigen
Um die Sache zu komplettieren poste ich auch mal meinen Code für die
login.jsp:
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!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=UTF-8" />
<link type="text/css" rel="stylesheet" href="style.css"/>
<%@ page language="java" %>
<%@ page import="BL.*, Hibernate.*, mapping.*, main.*, DAO.*, Tests.*" %>
<% //session.setAttribute("authorized", "yes"); %>
<title>Fotoalbum - Anmeldung</title>
</head>
<body>
<div id="wrapper">
<div id="header">Bitte Anmeldedaten eingeben</div>
<div id="navigation"> <%@include file='nav-1_outside.html'%></div>
<div id="haupt">
<div id="registerDiv">
<div class="case-top"><h2 class="form">Anmeldung</h2></div>
<div class="case">
<div id="search">
<form action="login" method="post" >
<table cellspacing="0" style="width: 100%;">
<tr><th align="right" style="width: 20%;" scope="row">Benutzername:</th><td><input type="text" name="user" value=""/></td></tr>
<tr><th align="right" style="width: 20%;" scope="row">Passwort:</th><td><input type="text" name="pass" value=""/></td></tr>
</table>
<br/>
<input type="submit" value="Anmelden" />
</form>
</div>
</div>
</div>
</div>
<!-- </form>-->
<%@include file='nav-2.html'%>
<div id="footer"><%@include file='footer.html'%></div>
</div>
</body>
</html>
Alles anzeigen
Vielleicht wisst ihr guten Rat. Ich komm nicht drauf.