简体   繁体   English

无法为JSP错误tomcat,mysql编译类

[英]Unable to compile class for JSP error tomcat,mysql

I'm trying to upload my jsp project to tomcat. 我正在尝试将我的jsp项目上载到tomcat。

Under picture is structure of my jsp project. 下面的图片是我的jsp项目的结构。

在此处输入图片说明

and when in insert.html's function trying to use insert.jsp, under error evoke. 当在insert.html的函数中尝试使用insert.jsp时,会引发错误。

this code is only insert data to mysql server. 此代码仅将数据插入mysql服务器。

在此处输入图片说明

DBConnection.java : 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 : 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 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? 如何避免此错误?

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 ?? 您能在您的tomcat webapps目录中查看吗? The file DBConnection.class just may not be present under WEB-INF/classes folder. 文件DBConnection.class可能仅不在WEB-INF / classes文件夹下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM