-1
我在執行tomcat 7服務器中的jsp文件時遇到以下錯誤。 請幫忙無法編譯JSP類:DataConnection無法解析爲類型
注:我是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文件
包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;
}
};