Problem:
I am facing a classNotFoundException when i try to connect jsp container to mysql container by running an web application(.html, .jsp files) in browser.
Note: It is executing as expected in Eclipse
Description:
I have created an "mysqlrep" image using below dockerfile and i am using this image name in docker-compose.
from ubuntu:14.04
run apt-get update
run apt-get install mysql-server -y
run apt-get install curl -y
RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
env set MYSQL_ROOT_PASSWORD= root
add my.sql /var/lib/mysql
run bash -c "/etc/init.d/mysql start && mysql -u root </var/lib/mysql/my.sql"
In above dockerfile, i created database using my.sql file as shown below
CREATE SCHEMA softwareag;
use softwareag;
create table users(
username varchar(10) primary key,
pwd varchar(10),
fname varchar(10),
lname varchar(10),
email varchar(30)
);
insert into users values('shashank','shas','shashank','g','sg@gmail.com');
CREATE USER "root"@"%" IDENTIFIED BY "root";
GRANT ALL PRIVILEGES ON *.* TO "root"@"%";
FLUSH PRIVILEGES;
Below is my docker-compose.yml where i am linking mysql container and jsp container
mysql:
image: mysqlrep1
container_name: mysqlcompose1
environment:
- MYSQL_ROOT_PASSWORD= root
ports:
- "0.0.0.0:3306:3306"
command: bash -c "/etc/init.d/mysql start && cd /var/lib/mysql && mysql -u root && sleep 50"
jsp:
build: .
container_name: jspcompose1
links:
- mysql
cap_add:
- SYS_PTRACE
ports:
- "8080:8080"
command: bash -c "/etc/init.d/tomcat7 start && ping 127.0.0.1 -c 100"
i am creating an jsp container in docker-compose using dockerfile. Inside dockerfile, using ubuntu as the base image and installing jdk, tomcat7 on top of it and mounted .html, .jsp files inside /var/lib/tomcat7/webapps/ROOT directory of jsp container.
Note: i also tried many syntax to set the classpath for mysql .jar file after adding mysql .jar to lib directories inside dockerfile but it doesnt solve my issue.
After running docker-compose up, at the same time i am accessing it in browser through http://system-ip-address:8080/index.html.
Note: In index .html, user click submit button after he enters his username & password, it redirects to signIn.jsp page to verify username/password by connecting to mysql database.
It works but when user click submit, it get redirected to signIn.jsp where it throws ClassNotFoundException.
This is my signIn.jsp file
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Sign In</title>
</head>
<body>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page isErrorPage="true" %>
<%
try{
String userid=request.getParameter("usr");
session.setAttribute("username",userid);
String pwd=request.getParameter("pwd");
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://mysql:3306/softwareag","root","root");
Statement st= con.createStatement();
ResultSet rs=st.executeQuery("select * from users where username='"+userid+"'");
if(rs.next())
{
if(rs.getString(2).equals(pwd))
{
response.sendRedirect("http://www.softwareag.com/in/");
}
}else
{
response.sendRedirect("http://localhost:8080/index.html");
}
}
catch(Exception e)
{
out.print("Exception:"+e);
}
%>
</body>
</html>
Can you suggest the solution to make it work ?
How and where to provide classpath for mysql-connector-java-5.1.5-bin.jar file ?