简体   繁体   English

无法使用Eclipse Juno编译JSP的类

[英]Unable to compile class for JSP using Eclipse Juno

I'm having trouble getting my JSP page to recognize my Java Class (DbSettings) I believe my file directory is set up correctly below. 我无法让我的JSP页面识别我的Java类(DbSettings),我认为我的文件目录在下面正确设置了。

the issue is crashing at this line: rs = DbSettings.getResultSet 问题在此行崩溃: rs = DbSettings.getResultSet

Can anyone point me into the right direction on how to get this resolved? 谁能为解决这个问题指明正确的方向?

RESOLVED: had to import the classes into the JSP files added imports at the top. 解决:必须将类导入到JSP文件中,并在顶部添加导入。

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

File Directory: Prj Name: Currency 文件目录: 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 (Can't get this class recognized in JSP file) 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 File snippet: 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 {
    %>

Stacktrace 堆栈跟踪

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)

Classes not within a package are discouraged in modern Java, to the point where they don't work in a number of cases. 在现代Java中,不鼓励不在包中的类在某些情况下不起作用。 Put your classes into packages (use a package statement at the top of the .java file)--all of them. 将您的类放入包中(使用.java文件顶部的package语句)。

I had to import the classes into the JSP files 我必须将这些类导入到JSP文件中

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

Solved this issue, Thank you everyone for your help 解决了这个问题,谢谢大家的帮助

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

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