javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/mysql/jdbc/Driver - java

I am trying to run simple code to connect with mysql. I m using eclipse and tomcat.
I have added mysql-connector-java-8.0.1.9.jar in Libraries:
Libraries-->mysql-->mysql-connector-java-8.0.1.9.jar
I have been at it for several hours adding and removing mysql-connector-java-8.0.1.9.jar to build path cannot get it running. Please help. Do I need to add any thing in run configuration??
This is the error on eclipse browser:
HTTP Status 500 – Internal Server Error
Type Exception Report
Message javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/mysql/jdbc/Driver
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/mysql/jdbc/Driver
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:599)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:500)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause
javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/mysql/jdbc/Driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:917)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:846)
org.apache.jsp.regCheck_jsp._jspService(regCheck_jsp.java:129)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:71)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause
java.lang.NoClassDefFoundError: com/mysql/jdbc/Driver
compute.DB.con(DB.java:21)
org.apache.jsp.regCheck_jsp._jspService(regCheck_jsp.java:100)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:71)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1951)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1794)
compute.DB.con(DB.java:21)
org.apache.jsp.regCheck_jsp._jspService(regCheck_jsp.java:100)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:71)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Note The full stack trace of the root cause is available in the server logs.
This is the output in console:
> Mar 16, 2020 4:57:27 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/Mysql] has started
Mar 16, 2020 4:57:27 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/Mysql] is completed
Mar 16, 2020 4:57:41 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/Mysql] threw exception [javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/mysql/jdbc/Driver] with root cause
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1951)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1794)
at compute.DB.con(DB.java:21)
at org.apache.jsp.regCheck_jsp._jspService(regCheck_jsp.java:100)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:71)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:492)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:165)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1195)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:654)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:319)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:834)
Try - 05 Trying to establish con in regCheck.jsp
Con method called Try 5A
Try 05a - Trying to connect
This is DB.java:
package compute;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.*;
public class DB {
final static String DB_URL = "jdbc:mysql://localhost:3306/new";
final static String USER = "admin";
final static String PASS = "admin";
public static Connection con() {
System.out.println("Con method called Try 5A");
Connection con;
try {
System.out.println("Try 05a - Trying to connect");
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
con = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("Try 05a- con established ");
return con;
}catch(Exception e) {
System.out.println(e);
return null;
}
}
public static Statement st() {
Statement stmt;
try {
stmt=DB.con().createStatement();
return null;
}catch(Exception e) {
System.out.println(e);
return null;
}
}
}
This is regCheck.jsp:
<%#page import="java.sql.Connection" %>
<%#page import="compute.DB" %>
<%#page import="java.sql.PreparedStatement" %>
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String user = request.getParameter("username");
System.out.println("Try - 05 Trying to establish con in regCheck.jsp");
Connection con = DB.con();
System.out.println("Preparing Statement in regCheck.jsp");
PreparedStatement p = con.prepareStatement("Insert into register(username)values(?)");
p.setString(1,user);
System.out.println("user::" +user);
int R = p.executeUpdate();
if(R!=0)
response.sendRedirect("index.html");
else
response.sendRedirect("register.jsp");
%>
</body>
</html>

The JDBC driver library is missing from your runtime CLASSPATH i.e. the CLASSPATH where Tomcat looks for the required classes in order to execute your compiled code.

I added mysql-connector-java-8.0.19.jar to Tomcat 7.0/Lib and now it's working find.
I removed it from Library and everywhere and it works.
I created new project with the same code and without adding mysql-connector-java-8.0.19.jar to any library or build path, it's running fine.
I found the instruction to add to tomcat somewhere on youtube.

Related

Error with JSP page - org.apache.jasper.JasperException

<%# page import = "java.sql.*" %>
<!-- Variables Declaration -->
<%!
String connectionURL = "jdbc:mysql://localhost:3306/Tamir";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
%>
<!-- Connecting to database "Tamir" -->
<%!
void ConnectDb(){
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL,"root","tamir");
statement = connection.createStatement();
} catch (Exception ex){
System.out.print("Error in connecting");
}
}
%>
<!-- Html Part Starts Here -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1255">
<title> Test Database </title>
</head>
<body>
<h1> test hello </h1>
<%
ConnectDb();
rs = statement.executeQuery("SELECT * FROM users");
out.println(rs.getString("nickname"));
rs.close();
%>
</body>
</html>
Error recieved:
error
and yes, I have the mysql connector in lib of web-inf.
Yes I have a database with the username Tamir and password tamir, and the table Users;
yes, i have tomcat installed and running.
I've been looking in the internet for ages, help would be appriciated. Cheers.
Edit: full error is as the following:
HTTP Status 500 - An exception occurred processing JSP page /select.jsp at line 34
type Exception report
message An exception occurred processing JSP page /select.jsp at line 34
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /select.jsp at line 34
31: <%
32: ConnectDb();
33: rs = statement.executeQuery("SELECT * FROM users");
34: out.println(rs.getString("nickname"));
35: rs.close();
36: %>
37:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
root cause
javax.servlet.ServletException: java.sql.SQLException: Before start of result set
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
org.apache.jsp.select_jsp._jspService(select_jsp.java:110)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
root cause
java.sql.SQLException: Before start of result set
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:790)
com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5212)
com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5135)
com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5174)
org.apache.jsp.select_jsp._jspService(select_jsp.java:98)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.47 logs.
Apache Tomcat/7.0.47
enter code here

Call Java method from JSP file

I have a problem with calling Java method from .jsp file. I converted my project into Maven but still have the same problem.
My .jsp file is in /db-reagencii/WebContent/reagents/reagents.jsp
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%#page import="cz.dbReagents.web.reagentsWeb.ReagentsWeb"%>
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Reagencie</title>
</head>
<body>
<jsp:include page="../WEB-INF/menu/menu.jsp"/>
Reagents
<jsp:useBean id="podnikyWeb" class="cz.dbReagents.web.reagentsWeb.ReagentsWeb" scope="request"/>
</body>
</html>
and i want call method from this class
package cz.dbReagents.web.reagentsWeb;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import cz.dbReagents.dto.reagents.Reagents;
public class ReagentsWeb implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
public Collection<Reagents> getReagents(){
ArrayList<Reagents> result = new ArrayList<Reagents>();
result.add(new Reagents("testovaci reagencie",11));
System.out.print(result.get(0).getName());
return result;
}
}
and this class
package cz.dbReagents.dto.reagents;
import java.io.Serializable;
public class Reagents implements Serializable{
private static final long serialVersionUID = 1L;
private String name;
private int sum;
public Reagents(){
}
public Reagents(String name, int sum){
this.name = name;
this.sum = sum;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSum() {
return sum;
}
public void setSum(int sum) {
this.sum = sum;
}
}
but when I tried to load page a got this error
VI 11, 2015 8:47:28 ODP. org.apache.catalina.core.StandardWrapperValve
invoke SEVERE: Servlet.service() for servlet [jsp] in context with
path [/db-reagencii] threw exception [/reagents/reagents.jsp (line:
17, column: 1) The value for the useBean class attribute
cz.dbReagents.web.reagentsWeb.ReagentsWeb is invalid.] with root cause
org.apache.jasper.JasperException: /reagents/reagents.jsp (line: 17,
column: 1) The value for the useBean class attribute
cz.dbReagents.web.reagentsWeb.ReagentsWeb is invalid. at
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
at
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)
at
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:149)
at
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1242)
at org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1196) at
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392) at
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2444) at
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2450) at
org.apache.jasper.compiler.Node$Root.accept(Node.java:474) at
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392) at
org.apache.jasper.compiler.Generator.generate(Generator.java:3529) at
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:251)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:374) at
org.apache.jasper.compiler.Compiler.compile(Compiler.java:354) at
org.apache.jasper.compiler.Compiler.compile(Compiler.java:341) at
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:662)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Is there a chance that I have bad configured server?
I have web.xml in /db-reagencii/WebContent/WEB-INF/web.xml and contains this:
<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_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Databáze Reagencií</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
I am using Tomcat 7.0.
This is my first web application in Java so I am sure that there is some stupid mistake but I can't find it.
Thanks for any advice :)
My error with scriplet.
VI 11, 2015 11:09:00 ODP.
org.apache.catalina.core.StandardWrapperValve invoke SEVERE:
Servlet.service() for servlet [jsp] in context with path
[/db-reagencii] threw exception [Unable to compile class for JSP:
An error occurred at line: [14] in the generated java file:
[/home/michal/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/db-reagencii/org/apache/jsp/reagents/reagents_jsp.java]
Only a type can be imported.
cz.dbReagents.web.reagentsWeb.ReagentsWebHandler resolves to a package
An error occurred at line: [15] in the generated java file:
[/home/michal/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/db-reagencii/org/apache/jsp/reagents/reagents_jsp.java]
Only a type can be imported. cz.dbReagents.dto.reagents.Reagents
resolves to a package
An error occurred at line: 18 in the jsp file: /reagents/reagents.jsp
ReagentsWebHandler cannot be resolved to a type 15: 16: Reagents 17: 18: <%
ReagentsWebHandler r = new ReagentsWebHandler(); %> 19: 20:
21:
An error occurred at line: 18 in the jsp file: /reagents/reagents.jsp
ReagentsWebHandler cannot be resolved to a type 15: 16: Reagents 17: 18: <%
ReagentsWebHandler r = new ReagentsWebHandler(); %> 19: 20:
21:
Stacktrace:] with root cause org.apache.jasper.JasperException: Unable
to compile class for JSP:
An error occurred at line: [14] in the generated java file:
[/home/michal/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/db-reagencii/org/apache/jsp/reagents/reagents_jsp.java]
Only a type can be imported.
cz.dbReagents.web.reagentsWeb.ReagentsWebHandler resolves to a package
An error occurred at line: [15] in the generated java file:
[/home/michal/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/db-reagencii/org/apache/jsp/reagents/reagents_jsp.java]
Only a type can be imported. cz.dbReagents.dto.reagents.Reagents
resolves to a package
An error occurred at line: 18 in the jsp file: /reagents/reagents.jsp
ReagentsWebHandler cannot be resolved to a type 15: 16: Reagents 17: 18: <%
ReagentsWebHandler r = new ReagentsWebHandler(); %> 19: 20:
21:
An error occurred at line: 18 in the jsp file: /reagents/reagents.jsp
ReagentsWebHandler cannot be resolved to a type 15: 16: Reagents 17: 18: <%
ReagentsWebHandler r = new ReagentsWebHandler(); %> 19: 20:
21:
Stacktrace: at
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
at
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
at
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:485)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:379) at
org.apache.jasper.compiler.Compiler.compile(Compiler.java:354) at
org.apache.jasper.compiler.Compiler.compile(Compiler.java:341) at
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:662)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
I got this error when I put only this lines into ragents.jsp
<%# page import="cz.dbReagents.web.reagentsWeb.ReagentsWebHandler " %> <h1>Hello World</h1>
VI 11, 2015 11:14:05 ODP.
org.apache.catalina.core.StandardWrapperValve invoke SEVERE:
Servlet.service() for servlet [jsp] in context with path
[/db-reagencii] threw exception [Unable to compile class for JSP:
An error occurred at line: [14] in the generated java file:
[/home/michal/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/db-reagencii/org/apache/jsp/reagents/reagents_jsp.java]
Only a type can be imported.
cz.dbReagents.web.reagentsWeb.ReagentsWebHandler resolves to a package
Stacktrace:] with root cause org.apache.jasper.JasperException: Unable
to compile class for JSP:
An error occurred at line: [14] in the generated java file:
[/home/michal/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/db-reagencii/org/apache/jsp/reagents/reagents_jsp.java]
Only a type can be imported.
cz.dbReagents.web.reagentsWeb.ReagentsWebHandler resolves to a package
Stacktrace: at
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
at
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
at
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:485)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:379) at
org.apache.jasper.compiler.Compiler.compile(Compiler.java:354) at
org.apache.jasper.compiler.Compiler.compile(Compiler.java:341) at
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:662)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
When I deploy war files into tomcat i got this error
VI 11, 2015 11:50:18 ODP. org.apache.catalina.core.ApplicationContext
log INFO: ContextListener: contextInitialized() VI 11, 2015 11:50:18
ODP. org.apache.catalina.core.ApplicationContext log INFO:
SessionListener: contextInitialized() VI 11, 2015 11:50:18 ODP.
org.apache.catalina.core.ApplicationContext log INFO: ContextListener:
attributeAdded('org.apache.jasper.compiler.TldLocationsCache',
'org.apache.jasper.compiler.TldLocationsCache#68ccc170') VI 11, 2015
11:50:45 ODP. org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path
[/db-reagencii] threw exception [Unable to compile class for JSP:
An error occurred at line: [14] in the generated java file:
[/home/michal/apps/apache-tomcat-7.0.62/work/Catalina/localhost/db-reagencii/org/apache/jsp/reagents/reagents_jsp.java]
Only a type can be imported.
cz.dbReagents.web.reagentsWeb.ReagentsWebHandler resolves to a package
Stacktrace:] with root cause org.apache.jasper.JasperException: Unable
to compile class for JSP:
An error occurred at line: [14] in the generated java file:
[/home/michal/apps/apache-tomcat-7.0.62/work/Catalina/localhost/db-reagencii/org/apache/jsp/reagents/reagents_jsp.java]
Only a type can be imported.
cz.dbReagents.web.reagentsWeb.ReagentsWebHandler resolves to a package
Stacktrace: at
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
at
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
at
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:485)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:379) at
org.apache.jasper.compiler.Compiler.compile(Compiler.java:354) at
org.apache.jasper.compiler.Compiler.compile(Compiler.java:341) at
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:662)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
you have an extra space before "page" in the JSP Import directive:
<%#page import="cz.dbReagents.web.reagentsWeb.ReagentsWeb"%>
It should be:
<%# page import="cz.dbReagents.web.reagentsWeb.ReagentsWeb"%>
I really hate using java sentences in JSP but if you want to do it this way, just modify your ReagentsWeb this way:
public class ReagentsWeb {
public Collection<Reagents> reagents;
public ReagentsWeb(){
reagents = this.getReagents();
}
public Collection<Reagents> getReagents(){
ArrayList<Reagents> result = new ArrayList<Reagents>();
result.add(new Reagents("testovaci reagencie",11));
return result;
}
}
In your JSP do this:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%#page import="cz.dbReagents.web.reagentsWeb.ReagentsWeb"%>
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Reagencie</title>
</head>
<body>
<jsp:include page="../WEB-INF/menu/menu.jsp"/>
Reagents
<%
for(Reagent r : reagents){
out.println(r.getName());
}
%>
</body>
</html>

JSP MySQL Class.forName error

I'm new to JSP. I'm trying to do a basic program of JSP & MySQL connectivity using ADT Eclipse. On running the index.jsp page, I get the following:
HTTP Status 500 - An exception occurred processing JSP page /index.jsp at line 24
type Exception report
message An exception occurred processing JSP page /index.jsp at line 24
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 24
21: String sql = "select usertype from userdetail";
22:
23: try {
24: Class.forName("com.mysql.jdbc.Driver");
25: con = DriverManager.getConnection(url, user, password);
26: ps = con.prepareStatement(sql);
27: rs = ps.executeQuery();
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
org.apache.jsp.index_jsp._jspService(index_jsp.java:141)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:126)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:190)
org.apache.jsp.index_jsp._jspService(index_jsp.java:85)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.30 logs.
Apache Tomcat/7.0.30
I downloaded MySQL Connector J jar and included it in the project
Thanks in advance...
Don't add the external jar. Download it and copy in project.
COPY it in WEB-INF--->lib(folder).
The error ,
javax.servlet.ServletException: java.lang.ClassNotFoundException:
com.mysql.jdbc.Driver
says that it couldn't find the class file .
So you should check for the mysql jar to the the project using ,
Project properties-> add jar
before that place the jar in folder somewhere inside the project or add through external jar option.
If you already added . trying remove and adding the jar file again
see how-to-add-mysql-driver-jar-file-in-eclipse and how-to-add-external-jar-without-eclipse for addtional reference

Calling java function in jsp page

I am having a java file named FaceDetection.java that has a function named FaceDetectionMain and that take two arguments .The java file dont have any main function.Now i call this java class file function in my jsp page like this :
FaceDetection.FaceDetectionMain(imagepath,imagename);
But am getting an exception as follow :
Apr 21, 2014 10:44:23 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/SharedCrpto1] threw exception [Unable to compile class for JSP:
An error occurred at line: 90 in the jsp file: /uploadwebcamimage.jsp
FaceDetection cannot be resolved
87: fos.write(imageData);
88: String imagepath=filesstore+"\\"+imagename+".png";
89:
90: Boolean flag=FaceDetection.FaceDetectionMain(imagepath,imagename);
91: %>
92: </body>
93: </html>
Stacktrace:] with root cause
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 90 in the jsp file: /uploadwebcamimage.jsp
FaceDetection cannot be resolved
87: fos.write(imageData);
88: String imagepath=filesstore+"\\"+imagename+".png";
89:
90: Boolean flag=FaceDetection.FaceDetectionMain(imagepath,imagename);
91: %>
92: </body>
93: </html>
Please help me remove this exception.
Full stackTrace for exception is :
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:97)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:457)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:352)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:339)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:344)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:182)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Using the default package isn't a good practice, and often causes problems such as the one you are having (you can't import the default package, so no need to try the page import directives) Try putting your class in a package and import it, you should find that it works properly.

ClassNotFoundException: com.mysql.jdbc.Driver. JDBC MySQL driver for web application [duplicate]

This question already has answers here:
How to install JDBC driver in Eclipse web project without facing java.lang.ClassNotFoundexception
(13 answers)
Closed 7 years ago.
So I have a .jar file for the MySQL JDBC driver, it is under my libraries source folder and I have the following code:
public static Connection getConnection() throws SQLException {
Connection conn = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://50.56.81.42:3306/GUEST_BOOK";
String user = "user";
String password = "pass";
conn = (Connection) DriverManager.getConnection(url, user, password);
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(InstantiationException e){
e.printStackTrace();
}catch(IllegalAccessException e){
e.printStackTrace();
}
return conn;
}
However, it always gives me this error:
INFO: Server startup in 645 ms
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at gbook.DbHelper.getConnection(DbHelper.java:14)
at gbook.DbHelper.getGuestBook(DbHelper.java:51)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:83)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Dec 1, 2011 1:41:05 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/JDBC-MySQL] threw exception [javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/mysql/jdbc/Connection] with root cause
java.lang.ClassNotFoundException: com.mysql.jdbc.Connection
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
at gbook.DbHelper.getGuestBook(DbHelper.java:52)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:83)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
Here's how I added the jar file. I created a lib folder and put the jar inside and then I go to configure build path in eclipse and added the jar inside the lib folder to the project.
You missed mysql-connector-j jar file in your classpath. Use "java -cp .:mysql.jar...". Ou. It's a webapp! Then put mysql jar file to WEB-INF/lib folder.
Right click Libraries ->Add JAR/Folder and choose mysql-connector-java.jar file
if you are using Apache Tomcat, you may have to add the driver to the path using "Configure Tomcat" in Java Tab.

Categories