jsp - 类型不匹配:无法从 void 转换为 ArrayList|| 在 JSP 文件中使用 Arraylist
问题描述
得到一个方法,它返回一个带有查询结果的 ArrayList:
public ArrayList<String> answerRequest(String table, String attribut) {
ArrayList<String> res = new ArrayList<String>();
try (Statement st = getMySQLConnection().createStatement();) {
ResultSet daten = st.executeQuery("SELECT " + table + "." + attribut + " from " + table);
while (daten.next()) {
res.add(daten.getString(1));
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return res;
}
这很好用,我在我的 JSP 文件中调用该方法,如下所示:
<%
ArrayList<String> res = new MySQLConnUtils().answerRequest("betreiber", "name");
for (int i = 0; i < res.size(); i++) {
out.println(res.get(i));
}
%>
我得到了这个错误,我没有落后,因为函数“MySQLConnUtils().answerRequest”清楚地返回了一个数组......
An error occurred at line: [17] in the jsp file: [/TESTJSP.jsp]
Type mismatch: cannot convert from void to ArrayList<String>
14: <body>
15:
16: <%
17: ArrayList<String> res = new MySQLConnUtils().answerRequest("betreiber", "name");
18: for (int i = 0; i < res.size(); i++) {
19: out.println(res.get(i));
20: }
我感谢您的帮助!
解决方案
推荐阅读
- pandas - 如何在 Pandas 中链接 .agg() 和 .assign() 函数
- angular - ionic-5:“StatusBarOriginal”类型不可分配给“Provider”类型
- html - 合并两个base64 url并生成一个PDF
- batch-file - 使用批处理文件替换文本文件中的字符串
- python - 如何在 Python 中提取 html 表的单个值?
- mongodb - 如何根据MongoDB聚合中的另一个数组对数组进行分组?
- python - 在上传到谷歌云存储 django 之前调整图像大小
- c# - 如何生成超过 1048576 行的 Excel 工作表
- c# - 如何对 Core MVC 控制器操作是否调用 ControllerBase.Problem() 进行单元测试
- android - SOFT_INPUT_MODE_CHANGED 是做什么的?