我需要顯示來自PL SQL表中的數據以進行分配。我將結果作爲HashMap並將其傳遞給JSP頁面。我如何在一個表格中顯示這些數據?我可以在這樣的JSTL標籤內使用HTML標籤嗎?我們如何迭代JSTL中的HashMap?
<c:forEach items="${employees}" var="employee">
<td>${employee.name}</td>
<td>${employee.city}</td>
<td>${employee.salary}</td>
<c:forEach>
還是有任何其他技術使用PL SQL在JSP頁面中打印表?
編輯: 這是我的代碼:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@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>
<h1>Employee Details</h1>
<form action="handler" method="post">
<table>
<tr>
<td>Employee ID</td>
<td>First Name</td>
<td>Last Name</td>
<td>Start Date</td>
<td>End Date</td>
<td>Salary</td>
<td>City</td>
<td>Description</td>
</tr>
<c:forEach items="${employees}" var="employee">
<tr>
<td>${employee.value.id}</td>
<td>${employee.value.fName}</td>
<td>${employee.value.lName}</td>
<td>${employee.value.startD}</td>
<td>${employee.value.endD}</td>
<td>${employee.value.salary}</td>
<td>${employee.value.city}</td>
<td>${employee.value.desc}</td>
</tr>
</c:forEach>
</table>
</form>
</body>
</html>
編輯2:
這是我創造了我的HashMap:
while (rs.next()) {
employee = new Employee(
rs.getString("EMPLOYEEID"),
rs.getString("FIRST_NAME"),
rs.getString("LAST_NAME"),
rs.getString("START_DATE"),
rs.getString("END_DATE"),
rs.getString("SALARY"),
rs.getString("CITY"),
rs.getString("DESCRIPTION")
);
System.out.println(employee.toString());
employees.put(rs.getString("EMPLOYEEID"), employee);
使用試試你的用' ' –
td
(idm習語)