-1

i have a problem to format time in Localdatetime pass from servlet to jsp. Here its my code:

<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>

But i show "deviceType cannot be resolved"

Can you help me/Thanks for all

1 Answers1

0

You can get the variable from the pageContext.

LocalDateTime stopTime = ((DeviceType) pageContext.getAttribute("deviceType")).getStopTime();
// replace DeviceType with the type of the variable deviceType
Unmitigated
  • 76,500
  • 11
  • 62
  • 80
  • Thanks for yr heilp. But when i type this: LocalDateTime stopTime = ((DeviceType) pageContext.getAttribute("deviceType")).getStopTime(); its warning DeviceType cannot be resolved to a type – Do Duy Linh May 16 '23 at 05:05
  • i have not import DeviceType yet. So it worked. Thanks u so much for ur help – Do Duy Linh May 16 '23 at 05:43