1
任何人都可以幫助我,我試圖將一個用戶列表從一個SQL表格調出到html上的下拉列表中。當從這個列表中選擇一個名字時,我希望它在一個名爲Notices的表中提出細節。我不確定問題出在我的代碼上。從數據庫中調用信息
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%--
Document : history
Created on : 12-Mar-2012, 03:49:35
Author :
--%>
<sql:query var="user" dataSource="jdbc/noticeboard">
SELECT username FROM registeredusers
</sql:query>
<sql:query var="noticesQuery" dataSource="jdbc/noticeboard">
SELECT N_id,postedon,messages,ack FROM notices order by N_id desc limit 1;
</sql:query>
<c:set var="noticesDetails" value="${noticesQuery.rows[0]}"/>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Notice Board</title>
</head>
<body>
<form action="one.jsp">
<strong>Select a username:</strong>
<select name="username">
<c:forEach var="row" items="${user.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>
</body>
</html>
<%--
Document : one
Created on : 26-Mar-2012, 07:35:21
Author :
--%>
<sql:query var="userQuery" dataSource="jdbc/noticeboard">
SELECT messages FROM notices WHERE user = ? <sql:param value="${param.user}"/>
</sql:query>
<c:set var="messageDetails" value="${userQuery.rows[0]}"/>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<table border="1">
<tr>
<td>ID</td>
<td>USERNAME</td>
<td>MESSAGE</td>
<td>DATE</td>
<td>ACK</td>
</tr>
<tr>
<td>${messageDetails.N_id}</td>
<td>${messageDetails.user}</td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>
你得到什麼錯誤?請發佈預期/實際輸出 – 2012-03-26 06:50:56
什麼也沒有發生,我想從數據庫中得到的名字出現在下拉框中,但是當我選擇一個並提交時,我希望它從表格中調出相應的數據,不 – user1162494 2012-03-26 06:56:17