Localdatetime中的格式化时间从servlet传递到jsp [重复]

0qx6xfy6  于 2023-05-21  发布在  其他
关注(0)|答案(1)|浏览(119)

此问题已在此处有答案

Use EL ${XY} directly in scriptlet <% XY %>(1个答案)
4天前关闭。
我在从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无法解析”
你能帮我吗/谢谢你

jv4diomz

jv4diomz1#

您可以从pageContext中获取变量。

LocalDateTime stopTime = ((DeviceType) pageContext.getAttribute("deviceType")).getStopTime();
// replace DeviceType with the type of the variable deviceType

相关问题