김명준
김명준

Reputation: 363

Unable to compile class for JSP error tomcat,mysql

I'm trying to upload my jsp project to tomcat.

Under picture is structure of my jsp project.

enter image description here

and when in insert.html's function trying to use insert.jsp, under error evoke.

this code is only insert data to mysql server.

enter image description here

DBConnection.java :

package com.exam;

import java.sql.*;

public class DBConnection {

    public static Connection getCon() throws SQLException {
        // TODO Auto-generated method stub

        Connection con = null;
        try{
            Class.forName("com.mysql.jdbc.Driver");
            String url="jdbc:mysql://localhost:3306/testdb";
            con=DriverManager.getConnection("url", "root", "kcclab");
            System.out.println("DB 연결 완료");
            con.close();
            return con;
        }
        catch(ClassNotFoundException cnfe){
            System.out.println("연결이 안되네요..."+cnfe.getMessage());
            return null;
        } 

    }

}

insert.jsp :

<%@page import="java.sql.SQLException" %>
<%@page import="java.sql.PreparedStatement" %>
<%@page language="java" contentType="text/html; charset=euc-kr"
pageEncoding="euc-kr" %>
<%@page import="java.sql.Connection" %>
<%@page import="com.exam.DBConnection" %>
<!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=euc-kr">
<title>Insert title here</title>
</head>
<body>
<%
    request.setCharacterEncoding("euc-kr");
    String id=request.getParameter("ID");
    String pwd=request.getParameter("pwd");

    Connection con=null;
    PreparedStatement pstmt=null;
    String sql="insert into members vlaues(?,?,sysdate)";
    int n=0;

    try{
        con=DBConnection.getCon();
        pstmt=con.prepareStatement(sql);
        pstmt.setString(1, id);
        pstmt.setString(2, pwd);

        n=pstmt.executeUpdate();
    }
    catch(SQLException se){
        System.out.println(se.getMessage());
    }
    finally{
        try{
            if(pstmt!=null) pstmt.close();
            if(con!=null) con.close();
        }
        catch(SQLException se){
            System.out.println(se.getMessage());
        }
    }
%>
<script type="text/javascript">
    if(<%=n%>>0){
        alert("���������� ȸ�����ԵǾ����ϴ�.");
        location.href="../index.html";
    }
    else{
        alert("ȸ�����Կ� �����߽��ϴ�.");
        history.go(-1);
    }
</script>
</body>
</html>

insert.html

<!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=euc-kr">
<title>Insert title here</title>
<style type="text/css">
    #regbox{width:300px;}
    #regbox label{display:block;    width:100px;    float:left; }
</style>
</head>
<body>
<form method="post" action="insert.jsp">
    <fieldset id="regbox">
        <legend>ȸ������</legend>
        <label for="id">���̵�</label>
        <input type="text" name="id"/><br/>
        <label for="pwd">��й�ȣ</label>
        <input type="password" name="pwd"/><br/>
        <input type="submit" value="����">
        <input type="reset" value="���"/>
    </fieldset>
</form>
</body>
</html>

How Can I avoid this error?

Upvotes: 0

Views: 397

Answers (1)

Ruhul
Ruhul

Reputation: 1030

As per my understanding this may happen when you are trying to import the class which is not present under the class path. Can you please have a look at on your tomcat webapps directory ?? The file DBConnection.class just may not be present under WEB-INF/classes folder.

Upvotes: 1

Related Questions