[英]Using JSP Scriplet along with JSON Model attributes
我從JSON響應中獲取屬性/參數作為EPOCH時間變量。 我想轉換為dd/MM/yyyy hh:mm:ss
格式並顯示在表格中
<tbody>
<c:if
test="${not empty jsonResult && not empty jsonResult.records}">
<c:forEach items="${jsonResult.records}" var="record">
<tr>
<td style="width:15%;"><img src="${record.attributes.P_Image_Path}" class="img-responsive" /></td>
<td style="width:15%;">${record.attributes.P_Description}</td>
<td style="width:55%;">${record.attributes.P_Username_Seller}</td>
<%
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
System.out.println(sdf.format( new java.util.Date(${record.attributes.P_Close_Time}));
%>
<td style="width:15%;">${record.attributes.P_Close_Time}</td>
</tr>
</c:forEach>
</c:if>
</tbody>
但是它無法編譯JSP。 我找不到如何使用JSON的scriplet和模型屬性值的組合
更新嘗試了此操作-不起作用
<c:set var="now" value="<%=new java.util.Date(${record.attributes.P_Close_Time}%>" />
<td style="width: 15%;"><fmt:formatDate pattern="dd/MM/yyyy hh:mm:ss" value="${now}" /></td>
嘗試了這個-不起作用
<td style="width: 15%;"><fmt:formatDate pattern="dd/MM/yyyy hh:mm:ss" value="<%=new java.util.Date(${record.attributes.P_Close_Time})%>" /></td>
嘗試了這個-不起作用
<td style="width: 15%;"><fmt:formatDate pattern="dd/MM/yyyy hh:mm:ss" value="<%=new java.util.Date(record.attributes.P_Close_Time)>" /></td>
您可以使用JSTL標簽
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:formatDate pattern="dd/MM/yyyy hh:mm:ss" value="${now}" />
http://www.tutorialspoint.com/jsp/jstl_format_formatdate_tag.htm
<%
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
Record record = (Record) pageContext.getAttribute("record");
System.out.println(sdf.format(new Date(record.getAttributes().getP_Close_Time())));
%>
! 請使用此代碼打印類並發布結果,以便我可以找出您正在使用的類:
<tbody>
<c:if
test="${not empty jsonResult && not empty jsonResult.records}">
<c:forEach items="${jsonResult.records}" var="record">
<tr>
<td style="width:15%;"><img src="${record.attributes.P_Image_Path}" class="img-responsive" /></td>
<td style="width:15%;">${record.attributes.P_Description}</td>
<td style="width:55%;">${record.attributes.P_Username_Seller}</td>
<%
//java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
//System.out.println(sdf.format( new java.util.Date(${record.attributes.P_Close_Time}));
Object record = pageContext.getAttribute("record");
System.out.println("page record: " + (record == null ? null : record.getClass().getName()));
%>
<td style="width:15%;">${record.attributes.P_Close_Time}</td>
</tr>
</c:forEach>
</c:if>
</tbody>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.