我一直在开发一个连接到填充指定字段的数据库的网络应用程序。它基本上是一个netbeans 教程的编辑。好吧,我已经设置了数据库并通过在响应页面上填充所有信息的表来测试它。当我从列表中选择要查看的标题之一时,index.jsp 出现了问题。我使用标题而不是 ID 号来选择书籍:
SELECT titlefk FROM BookList
代替:
SELECT id, titlefk FROM BookList
因为下拉框会同时显示 ID 和 Title 作为选项。选择书名并单击提交键后,它应该使用数据库中的相应信息填充下一页。
网站图片:http: //imgur.com/a/kVEMN
上表是检查数据库是否连接的临时措施。我在数据库中选择了第三个选项,但我的 response.jsp 一直在填充第一本书的信息。我不确定我在代码中遗漏了什么,但我希望有人能指出我正确的方向。
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<sql:query var="books" dataSource="jdbc/IFPBOOKLISTRT">
SELECT titlefk FROM BookList
</sql:query>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>IFPBOOKLIST Homepage</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>Welcome to IFPBOOKLIST, My Personal Book Selection</h1>
<table border="0">
<thead>
<tr>
<th>Here you will find my personal books to-do list</th>
</tr>
</thead>
<tbody>
<tr>
<td>To view details, select a book below</td>
</tr>
<tr>
<td><form action="response.jsp">
<strong>Select a book:</strong>
<select name="subject_id">
<c:forEach var="row" items="${books.rowsByIndex}">
<c:forEach var="column" items="${row}">
<option value="<c:out value="${column}"/>"><c:out value="${column}"/></option>
</c:forEach>
</c:forEach>
</select>
<input type="submit" value="submit" name="submit" />
</form>
</td>
</tr>
</tbody>
</table>
</body>
这是 response.jsp
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<sql:query var="bookQuery" dataSource="jdbc/IFPBOOKLISTRT">
SELECT * FROM BookList,Book
WHERE Book.id=BookList.id
</sql:query>
<c:set var="bookDetails" value="${bookQuery.rows[0]}"/>
<table border="1">
<!-- column headers -->
<tr>
<c:forEach var="columnName" items="${bookQuery.columnNames}">
<th><c:out value="${columnName}"/></th>
</c:forEach>
</tr>
<!-- column data -->
<c:forEach var="row" items="${bookQuery.rowsByIndex}">
<tr>
<c:forEach var="column" items="${row}">
<td><c:out value="${column}"/></td>
</c:forEach>
</tr>
</c:forEach>
</table>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>${bookDetails.title}</title>
</head>
<body>
<table border="0">
<thead>
<tr>
<th colspan="2">${bookDetails.title}</th>
</tr>
<tr>
<td>Edition: <a href="placeholder">${bookDetails.edition}</a></td>
</tr>
</thead>
<tbody>
<tr>
<td>
<strong>Description: </strong>
</td>
<td>
{placeholder}
</td>
<link rel="stylesheet" type="text/css" href="style.css">
</tr>
<tr>
<td>
<strong>Publisher </strong>
</td>
<td>
${bookDetails.publisher}
</td>
</tr>
<tr>
<td>
<strong>
Published Date
</strong>
</td>
<td>
${bookDetails.datePublished}
</td>
</tr>
<tr>
<td>
<strong>Author </strong>
</td>
<td>
${bookDetails.author}
</td>
</tr>
<tr>
<td>
<strong>isbnNumber </strong>
</td>
<td>
<a href="placeholder">${bookDetails.isbnNumber}</a>
<br>
</td>
</tr>
<tr>
<td>
<strong>Amazon Link: </strong></td>
<td>
<a href="placeholder">${bookDetails.amazonLink}</a>
<br>
</td>
</tr>
</tbody>
</table>
</body>