2016-01-02 71 views
1

我有類DBBase定義爲我的應用程序如下:我不能叫從JSP頁面可變參數的方法

public class DBBase { 
    public static void close(Statement stmt) { 
     try { 
      if (stmt != null) stmt.close(); 
     } catch (Exception ex) { 
      logger.error("Exception:(", ex); 
     } 
    } 

    public static void close(ResultSet resultSet) { 
     try { 
      if (resultSet != null) resultSet.close(); 
     } catch (Exception ex) { 
      logger.error("Exception:(", ex); 
     } 
    } 

    public static void close(Connection con) { 
     try { 
      if (con != null) con.close(); 
     } catch (Exception ex) { 
      logger.error("Exception:(", ex); 
     } 
    } 

    public static void close(Object... closeable) { 
     for (Object obj : closeable) { 
      if (obj != null) { 
       if (obj instanceof Connection) close((Connection) obj); 
       else if (obj instanceof ResultSet) close((ResultSet) obj); 
       else if (obj instanceof Statement) close((Statement) obj); 
      } 
     } 
    } 
} 

當我調用close方法DBBase.close(con, stmt, resSet)從另一個類,一切工作正常,但是當我打電話從JSP頁面這個方法我得到了以下錯誤:

An error occurred at line: 20 in the jsp file: /admin/test.jsp 
Generated servlet error: 
The method close(Statement) in the type DBBase is not applicable for the arguments (Connection, Statement, ResultSet) 

這是我的JSP頁面:

<%@ page import="java.sql.ResultSet" %> 
<%@ page import="java.sql.Statement" %> 
<%@ page import="java.sql.Connection" %> 
<%@ page import="db.DBBase" %> 
<%@ page contentType="text/html;charset=UTF-8" language="java" %> 

<% 
    Connection con = null; 
    Statement stmt = null; 
    ResultSet resSet = null; 

    try { 
     // Some code here 
    } catch (Exception ex) { 
     ex.printStackTrace(); 
    } finally { 
     DBBase.close(con, stmt, resSet); 
    } 
%> 
<html> 
<head> 
    <title>Test JSP File</title> 
</head> 
<body> 

</body> 
</html> 

我的JDK版本是1.7.0._51,語言級別爲7

問題是什麼?

UPDATE

這是我的服務器和JSP CONFIGS:

Server Version: Apache Tomcat/5.5.17 
Servlet Version: 2.4 
JSP Version: 2.0 

其實我有JBoss的4.0.4 GA

UPDATE

關於向@ AlexC的評論我必須改變我的JBoss版本才能使用可變參數。

+0

嘗試發佈您的jsp頁面? – Abdelhak

+0

@Abdelhak添加 –

+0

如果您將前3種方法設爲私有,它會起作用嗎? –

回答