无法使用Eclipse Juno编译JSP类

时间:2015-01-08 02:49:43

标签: java eclipse jsp

我无法让我的JSP页面识别我的Java类(DbSettings)我相信我的文件目录在下面正确设置。

问题是在这一行崩溃: rs = DbSettings.getResultSet

有人能指出我如何解决这个问题的正确方向吗?

已解决:必须将类导入JSP文件 在顶部增加了进口。

<%@page import="classes.DbSettings"  %>
<%@page import="classes.DateValidator"  %>

文件目录: Prj名称:货币

Currency
-Deployment Description
-JAX-WS Web Services
-Java Resources
--src
---classes (Package)
----DateValidator.java
----DbSettings.java
--Libraries
----Apache
----EAR Libraries
----JRE
----Web App

-JavaScript Resources (default sub cats)
-build
-libs
ojdbc7.jar

-WebContent
--META-INF
--WEB-INF
---file.jsp
---file.jsp
---file.jsp

X .classpath
X .project

DbSettings.java (无法在JSP文件中识别此类)

package classes;  <--- New Package
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class DbSettings {
    private static Connection getConnection() throws Exception {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection conn = null;
        conn = DriverManager.getConnection(
                "jdbc:oracle:thin:@uschduxcls004sg09:1527:xxxxx", "xxxxx",
                "xxxxx");
        return conn;

    }

    public static final ResultSet getResultSet(String command) throws Exception {
        Connection conn = getConnection();
        Statement stmt = null;
        stmt = conn.createStatement();
        System.out.println("Statement was Succesful");
        ResultSet rs = null;
        rs = stmt.executeQuery(command);
        System.out.println("Query was Succesful");
        return rs;

    }
}

JSP文件摘要:

<%@page import="java.util.Calendar"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="classes.DbSettings"  %>
<%@page import="classes.DateValidator"  %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
<script language="javascript">
    // Set frametest1 level
    level = 0;

    function submitCurrency() {
        var valid = checkForm(document.currency_form);

        if (valid)
            document.currency_form.submit();
    }

    function checkForm(theForm) {
        // This function validates the entries entered by the user before passing the values
        // to the next page.

        // Check number of units
        if (theForm.txtUnits.value == "") {
            alert("Please enter the number of units you wish to convert.");
            theForm.txtUnits.focus();
            return (false);
        } else {
            result = isNaN(theForm.txtUnits.value);
            if (result == true) {
                alert("Please enter only numeric values in the \"Units\" field. No commas or other characters are needed or recognized.");
                theForm.txtUnits.focus();
                return (false);
            }
        }
        return true;
    }
</script>
</head>
<body>
    <%
        // Declare variables
        boolean fEmptyRecordset, fFirstPass, fNeedRecordset;
        int i; // as Integer
        fEmptyRecordset = false;
        fFirstPass = true;
        fNeedRecordset = true;
        ResultSet rs = null;
        String message = null;
        try {
            rs = DbSettings
                    .getResultSet("SELECT BLMBG_CURR_CODE,BLMBG_CURR_NAME FROM AON_CURRENCY_SDO ORDER BY BLMBG_CURR_NAME");
            fEmptyRecordset = rs.first();
        } catch (Exception ex) {
            fEmptyRecordset = true;
            message = ex.getMessage();
        }
        String aMonth = "";
        int aDate, aYear;
        if ("results".compareToIgnoreCase(request.getParameter("action")) == 0) {
            aMonth = request.getParameter("selMonth");
            aDate = Integer.parseInt(request.getParameter("selDate"));
            aYear = Integer.parseInt(request.getParameter("selYear"));
        } else {
            switch (Calendar.getInstance().get(Calendar.MONTH)) {
            case Calendar.JANUARY:
                aMonth = "JAN";
            case Calendar.FEBRUARY:
                aMonth = "FEB";
            case Calendar.MARCH:
                aMonth = "MAR";
            case Calendar.APRIL:
                aMonth = "APR";
            case Calendar.MAY:
                aMonth = "MAY";
            case Calendar.JUNE:
                aMonth = "JUN";
            case Calendar.JULY:
                aMonth = "JUL";
            case Calendar.AUGUST:
                aMonth = "AUG";
            case Calendar.SEPTEMBER:
                aMonth = "SEP";
            case Calendar.NOVEMBER:
                aMonth = "NOV";
            case Calendar.DECEMBER:
                aMonth = "DEC";
            }
            aDate = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
            aYear = Calendar.getInstance().get(Calendar.YEAR);
        }
        if (message != null || fEmptyRecordset) {
            out.println("<tr><td>");
            out.println(message);
            out.println("</td></tr>");
    %>
    <%
        } else {
    %>

堆栈跟踪

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 53 in the jsp file: /currency_form.jsp
DbSettings cannot be resolved
50:         ResultSet rs = null;
51:         String message = null;
52:         try {
53:             rs = DbSettings
54:                     .getResultSet("SELECT BLMBG_CURR_CODE,BLMBG_CURR_NAME FROM AON_CURRENCY_SDO ORDER BY BLMBG_CURR_NAME");
55:             fEmptyRecordset = rs.first();
56:         } catch (Exception ex) {


Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:485)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:379)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

2 个答案:

答案 0 :(得分:1)

现代Java中不鼓励不在包中的类,以至于它们在许多情况下都不起作用。将您的类放入包中(使用.java文件顶部的package语句) - 所有这些语句。

答案 1 :(得分:0)

我必须将类导入JSP文件

<%@page import="classes.DbSettings" %>
<%@page import="classes.DateValidator" %>

解决了这个问题,谢谢大家的帮助