Java JSP/MYSQL Dynamic Web Project

Motrip90

Cadet 3rd Year
Registriert
Sep. 2016
Beiträge
32
Hallo Leute, ich arbeite aktuell an einem Uni- Projekt, doch leider komme ich nicht weiter...

Ich habe eine LoginView, LoginAppl, UserBean und MySqlAccess


LoginView:

HTML:
<div class="container">
    <div class="row row-centered">
    	<div class="col-md-4 col-md-offset-4">
    		<div class="panel panel-default">
			  	<div class="panel-heading">
			    	<h3 class="panel-title">Bitte Loggen Sie sich ein!</h3>
			 	</div>
			  	<div class="panel-body">
			    	<form accept-charset="UTF-8" role="form" action="./LoginAppl.jsp" method="get">
                    <fieldset>
			    	  	<div class="form-group">
			    		    <input class="form-control" placeholder="Benutzername (E-Mail)" name="email" type="email">
			    		</div>
			    		<div class="form-group">
			    			<input class="form-control" placeholder="Passwort" name="password" type="password" value="">
			    		</div>
			    		<div class="checkbox">
			    	    	<label>
			    	    		<input name="remember" type="checkbox" value="Remember Me"> Remember Me
			    	    	</label>
			    	    </div>
			    		<input class="btn btn-lg btn-success btn-block" type="submit" name ="login" value="Login">
			    	
			      	
                      <hr/>
            
                    <input class="btn btn-lg btn-facebook btn-block" type="submit" name = "zurreg" value="Account Anfordern">
			      </fieldset>
			    </form>
			    </div>
			  
			</div>
		</div>
	</div>
</div>

LoginAppl:

HTML:
<%! public String denullify(String s){
	return (s==null)?"":s;
} %>
<%
String email   = request.getParameter("email");
String password = request.getParameter("password");

String login = this.denullify(request.getParameter("login"));
String zurreg = this.denullify(request.getParameter("zurreg"));

if (login.equals("Login")){
user.setEmail(email);
user.setPassword(password);
boolean emailPwExists = false;
		
try{
	emailPwExists = user.checkEmailPassword();
}catch (Exception e){
	e.printStackTrace();
	msg.setSystemfehler();
	response.sendRedirect("./LoginView.jsp");
}
	if(emailPwExists){
		user.setAngemeldet(true);
		msg.setPortalWelcome();
		response.sendRedirect("./StartseiteAppl.jsp?comeFrom=LoginAppl");
		
	}else{
		msg.setUserDoesNotExist();
		response.sendRedirect("./LoginView.jsp");
	}

	
		
	
		
		
	

	
}else if (zurreg.equals("Account Anfordern")){

	// hier evtl. noch Msg setzen
	response.sendRedirect("./RegAppl.jsp");
}else{
	// hier evtl. noch Msg setzen
	response.sendRedirect("./LoginView.jsp");	
}

%>

UserBean:

Code:
	public boolean checkEmailPassword() throws ClassNotFoundException, SQLException{
		// prüfen Sie, ob this.userid UND this.password in der Tabelle USER vorkommt
		// true - ja, kommt vor; false - nein, userid / pw-Kombi ist falsch
		String sql = "SELECT * FROM TEST.USER WHERE EMAIL = ? AND PASSWORD = ?";
		System.out.println(sql);
		Connection dbConn = new DB2Access().getConnection();
		PreparedStatement prep = dbConn.prepareStatement(sql);
		prep.setString(1, this.email);
		prep.setString(2, this.password);
		ResultSet dbRes = prep.executeQuery();
		return dbRes.next();
	}



MySqlAccess

Code:
package de.hs_lu.bw.jdbc;

import java.sql.SQLException;

public class DB2Access extends JDBCAccess {

	public DB2Access() throws SQLException, ClassNotFoundException {
		super();
	}
	public void setDBParms(){
		dbDrivername = "com.mysql.jdbc.Driver";
		dbURL = "jdbc:mysql://localhost/test";
		dbUser = "root";
		dbPassword = "123456";
	
	}
	public static void main(String[] args) throws SQLException, ClassNotFoundException{ 
		new DB2Access();
	}
}


Sobald ich das ausführe und auf "Login" klicke, egal ob die Daten Stimmen oder nicht, kommt immer Fehler:

HTTP Status 500 - java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed

Code:
SELECT * FROM TEST.USER WHERE EMAIL = ? AND PASSWORD = ?
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1166)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at de.hs_lu.bw.jdbc.JDBCAccess.createConnection(JDBCAccess.java:31)
	at de.hs_lu.bw.jdbc.JDBCAccess.<init>(JDBCAccess.java:18)
	at de.hs_lu.bw.jdbc.DB2Access.<init>(DB2Access.java:8)
	at beans.UserBean.checkEmailPassword(UserBean.java:111)
	at org.apache.jsp.jsp.LoginAppl_jsp._jspService(LoginAppl_jsp.java:161)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
Okt 03, 2016 12:35:31 PM org.apache.catalina.core.StandardWrapperValve invoke
SCHWERWIEGEND: Servlet.service() for servlet [jsp] in context with path [/SchulApp] threw exception [java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed] with root cause
java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
	at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:494)
	at org.apache.jsp.jsp.LoginAppl_jsp._jspService(LoginAppl_jsp.java:174)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
 
Hallo mal wieder ;)

Du musst den Stacktrace von oben nach unten lesen und ggf. gucken, ob nicht irgendwo ein Caused by auftaucht.

Die relevante Fehlermeldung für Dich ist:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Du weißt, was das bedeutet? Ihr habt den Datenbanktreiber (mysql.jar oder so ähnlich) nicht im Classpath Eures Projekts mit drin.
 
Hey Faust, das war mein erster Gedanke aber wenn ich Access ausführe kommt:

Code:
DB2-Treiber erfolgreich geladen
Mon Oct 03 12:57:04 CEST 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Datenbankverbindung erfolgreich angelegt

Habe auch eine AppInstallUserTable und wenn ich die ausführe, klappt es ebenfalls

Code:
DB2-Treiber erfolgreich geladen
Mon Oct 03 12:58:13 CEST 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Datenbankverbindung erfolgreich angelegt
DB2-Treiber erfolgreich geladen
Mon Oct 03 12:58:13 CEST 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Datenbankverbindung erfolgreich angelegt
DROP TABLE USER
SQL-Befehl erfolgreich ausgeführt
CREATE TABLE USER(VORNAME   CHAR(16)     NOT NULL, PASSWORD CHAR(32)     NOT NULL            , ACTIVE   CHAR(1)      NOT NULL DEFAULT 'N', ADMIN    CHAR(1)      NOT NULL DEFAULT 'N', NAME VARCHAR(256) NOT NULL            , EMAIL    VARCHAR(256) NOT NULL PRIMARY KEY)
SQL-Befehl erfolgreich ausgeführt
 
Das ergibt keinen Sinn. Auf der einen Seite versucht Deine JavaApp per Mysql einen Mysql-Server zu erreichen und nun kommst Du mit IBMs DB/2. Was denn nun?
 
Ah das mit IBM DB2 ist noch von Vorlesung, habe es auf MySql angepasst (daher noch der Text mit DB2)

in Build Path ist MySql connector drin. Die Access erstellt Verbindung erfolgreich, löscht die aktuelle Tabelle und erstellt neue.

Also klappt eig. Mysql aber sobald ich das mit "Login" oder so anwende kommt es so eine Fehlermeldung (das mysql fehlt??)
 
Du musst unterscheiden: Build Classapth und Runtime Classpath!

Der Build-Classpath ist nötig für das erfolgreiche Übersetzen Deines Projekts. Da Du gegen JDBC programmierst (und nicht gegen den Mysql-Treiber), brauchst Du hier den Treiber gar nicht. Der muss beim Runtime-Classpath (im Eclipse-Launcher bzw. im Application Server!) enthalten sein.
 
ah.. okey höre ich zum ersten mal :( , wir haben es immer in Build Classpath rein gemacht damals (IBM DB2)

wo finde ich die "Runtime Class Path einstellungen"?

Bzw. bin grad drin und da ist schon MySql Connector enthalten
 
Zuletzt bearbeitet:
Wie startest Du denn Projekt? Vermutlich aus Eclipse, sodass Du dort bei Deinem WAR-Projekt "Run As..." -> "Run on server" auswählst, oder? Dementsprechend muss Du nun sicherstellen, dass in Deinem WAR der mysql-Treiber mit drin ist.
 
Zurück
Oben