【发布时间】:2021-07-14 13:04:38
【问题描述】:
我正在尝试将 jsp 与 Java 一起使用,因此我创建了函数 getBestellung() 。此函数连接到我的数据库并从中获取一些条目。该方法本身有效,但是当我尝试获取返回值时,我的 Tomcat 服务器上出现以下错误:org.apache.jasper.JasperException: Cannot find any information on property [data] in a bean of type [com.example.CSA_Server.DBFunc]
这是类的样子:
import com.example.CSA_Server.Bestellung;
import org.omg.CORBA.PUBLIC_MEMBER;
import java.sql.*;
public class DBFunc implements secrets{
public static Connection conn() throws SQLException {
Connection conn = DriverManager.getConnection(url, user, password);
System.out.println("Verbindung wurde hergestellt");
return conn;
}
public static String getBestellung() throws SQLException{
Connection conn = conn();
String query = "SELECT * FROM Bestellung";
Statement statement = conn.createStatement();
ResultSet result = statement.executeQuery(query);
Bestellung b1 = null;
while(result.next()) {
long bID = result.getLong("B-ID");
long kID = result.getLong("K-ID");
b1 = new Bestellung(bID, kID);
}
String string = String.valueOf(b1);
conn.close();
//System.out.println(string);
return string;
}
}
JSP 看起来像:
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<jsp:useBean id="time" class="com.example.CSA_Server.TimeServlet" scope="request" />
<jsp:useBean id="data" class="com.example.CSA_Server.DBFunc" scope="request" />
<!DOCTYPE html>
<html>
<head>
<title>JSP - Hello World</title>
</head>
<body>
<h1><%= "Hello World!" %>
</h1>
<p>Das ist ein Probetext</p>
<br/>
<a href="hello-servlet">Hello Servlet</a>
<LI>Hallo du da</LI>
<LI><jsp:getProperty name="time" property="time"/></LI>
<LI>Du bist: <%request.getParameter("name");%></LI>
<p><jsp:getProperty name="data" property="data"/></p>
<p>Data: <%request.getParameter("data");%></p>
</body>
</html>
大多数时候,当我刷新页面时没有错误。没有错误时显示以下值:class com.example.CSA_Server.DBFunc
多次刷新后出现上述错误。
getBestellung() 函数有问题还是 jsp 语法错误?
【问题讨论】:
-
这段代码 和另一个类似的是scriptlet。 Scriptlet 不打印任何内容。此外,按照您编写它们的方式,它们什么也不做。您的意思是让它们成为“JSP 表达式”吗?