无法为JSP编译类:无法将DataConnection解析为类型

时间:2016-08-16 19:05:42

标签: java jsp

我在tomcat 7服务器上执行jsp文件时遇到以下错误。 请帮忙

注意:我是jsp的新手,甚至是java,所以请详细解释一下。

An error occurred at line: 26 in the jsp file: /checkLoginRedirect.jsp
DataConnection cannot be resolved to a type
23: 
24:     try
25:     {
26:         DataConnection cs = new DataConnection();
27:         int res = cs.getResultSet("select * from mnpgui",0);
28:         
29:         if(res==1)

Jsp文件

 <%@ 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>NDT</title>
</head>
<body>
<%@ page import = "com.dcddesigns.utilities.DataConnection.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "java.io.*" %>
<%@ page import = "java.sql.*" %>


<%
    String admin = request.getParameter("adminID");
    String password = request.getParameter("adminPW");
    session.setAttribute("userName",admin);
%>

<%

    try
    {
        DataConnection cs = new DataConnection();
        int res = cs.getResultSet("select * from mnpgui",0);

        if(res==1)
        {
            response.sendRedirect("HomePage.jsp");

        }
        else
        {
            response.sendRedirect("loginFailed.jsp");
        }
    }
    catch(Exception e)
    {
        e.printStackTrace(); 
    }

%>

</body>
</html>

java文件

package com.dcddesigns.utilities;

public class DataConnection {

    private java.sql.Statement stmt;
    private java.sql.Connection conn;
    private java.sql.ResultSet rs;


    public DataConnection()  {
        try {
            Class.forName("org.postgresql.Driver").newInstance();
            conn =  java.sql.DriverManager.getConnection("jdbc:postgresql://localhost/db_name?user=username&password=password");
            stmt = conn.createStatement();
            }
        catch (java.sql.SQLException sqle)  {
            sqle.printStackTrace();
            }
        catch (Exception e) {
            e.printStackTrace();
            }
        }


    public void killOpenObjects()   {
        try {
            if (stmt != null)    {
                stmt.close();
                }
            if (conn != null)    {
                conn.close();
                }
            }
        catch (java.sql.SQLException e)  {
            System.out.println("Exception in killOpenObjects");
            e.printStackTrace();
            }
        }


    public java.sql.ResultSet getResultSet(String query, boolean killTrigger)   {
        try {
            rs = stmt.executeQuery(query);
            }
        catch (java.sql.SQLException e) {
            System.out.println(query);
            System.out.println("Exception in DataConnection get ResultSet");
            e.printStackTrace();
            }
        finally {
            if (killTrigger)    {
                killOpenObjects();
                }
            }
        return rs;
        }


    public int updateTable(String query, boolean killTrigger)   {
        int rows = 0;
        try {
            rows = stmt.executeUpdate(query);
            }
        catch (java.sql.SQLException e) {
            if (e.getMessage().indexOf("Invalid argument value: Duplicate entry") == -1)     {
                System.out.println(e.getMessage());
                System.out.println(query);
                }
            }
        finally {
            if (killTrigger)    {
                killOpenObjects();
                }
            }
        return rows;
        }
};

1 个答案:

答案 0 :(得分:0)

显然应该是

Exception

而不是<%@ page import = "com.dcddesigns.utilities.DataConnection" %>