我通过stackoverflow搜索了这个错误,所有与此相关的答案似乎都不适用于我的情况(或者我忽略了那些答案中的某些内容)。无论如何,我是一个自学新手Java爱好者,所以任何帮助将不胜感激。
Tomcat中的类路径是'/webapps/ROOT/WEB-INF/classes/VidCollPkg/feedData.class'。 我的jsp文件位于'webapps / appletv'。
以下是错误日志的摘录:
Dec 31, 2012 12:41:48 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/appletv] threw exception [/select.jsp (line: 11, column: 0) The value for the useBean class attribute vidCollPkg.feedData is invalid.] with root cause
org.apache.jasper.JasperException: /select.jsp (line: 11, column: 0) The value for the useBean class attribute vidCollPkg.feedData is invalid.
以下是类文件的代码(成功编译):
package vidCollPkg;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class feedData {
java.sql.Connection con;
public feedData() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost/VideoDB? user=usr&password=pwd");
}
public ArrayList<String> getUnis() throws SQLException {
ArrayList<String> vidList = new ArrayList<String>();
String tryquery = "SELECT title FROM videoDB.vidtb ORDER BY title";
java.sql.Statement stmt2 = con.createStatement();
ResultSet rs1 = stmt2.executeQuery(tryquery);
while (rs1.next()) {
vidList.add(rs1.getString("title"));
}
return vidList;
}
}
以下是我的jsp文件的代码:
<%@ page contentType="text/html; charset=UTF-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Rate video</title>
</head>
<body>
<jsp:useBean id="obj" scope="page" class="vidCollPkg.feedData" />
<h1 align="center">RATE VIDEO</h1> <br>
<form name="frm" action="updateRecord.jsp">
Title: <select name="title">
<c:forEach var="title" items="${obj.vids}">
<option value="${title}">${title}</option>
</c:forEach>
</select><br>
Date Viewed: <input type="text" name="sDateVwd"><br>
Rating: <input type="text" name="rating"><br>
Comments: <br /><textarea name="comments" cols="40" rows="6"></textarea><br>
<input type="submit" value="Rate Video"><br />
<input type="reset" value="Reset" />
</form>
</body>
</html>
我觉得这很简单,我在俯瞰。在此先感谢您的帮助。
答案 0 :(得分:0)
将vidCollPkg添加到jsp中页面标记的import部分,并将jsp:useBean类更改为'feedData'。