我在从 servlet 到 jsp 的 Localdatetime 中格式化时间时遇到问题。 这是我的代码:
<c:forEach items="${listDeviceType}" var="deviceType">
<tbody>
<tr>
<td>${deviceType.ID}</td>
<td>${deviceType.name}</td>
<td>
<%
LocalDateTime stopTime = deviceType.getStopTime();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
String formattedStopTime = stopTime.format(formatter);
%>
</td>
<td>${deviceType.startTime}</td>
<td>${deviceType.resetTime}</td>
<td>
<a href="admin-devicetypeedit?dTID=${deviceType.ID}" class="badge rounded-pill bg-primary">
<i class="fa fa-edit"></i>
Edit
</a>
<form action="admin-devicetypedelete" method="POST" onsubmit="return confirm('Are you sure you want to delete this item?');">
<input type="hidden" name="dTID" value="${deviceType.ID}">
<button type="submit" class="badge rounded-pill bg-danger">
<i class="fa fa-trash-o">Delete</i>
</button>
</form>
</td>
</tr>
</tbody>
</c:forEach>
但是我显示“deviceType cannot be resolved”
你能帮我吗/谢谢大家
您可以从
pageContext
.中获取变量
LocalDateTime stopTime = ((DeviceType) pageContext.getAttribute("deviceType")).getStopTime();
// replace DeviceType with the type of the variable deviceType