Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将模型属性传递给JSP中本身返回值的javascript函数_Javascript_Java_Html_Jsp_Spring Mvc - Fatal编程技术网

如何将模型属性传递给JSP中本身返回值的javascript函数

如何将模型属性传递给JSP中本身返回值的javascript函数,javascript,java,html,jsp,spring-mvc,Javascript,Java,Html,Jsp,Spring Mvc,我必须在jsp页面本身中格式化从控制器[Spring]收到的日期。 以下是JSP文件: 我是否可以以某种方式使用此函数,或者其他任何替代方法是否适用于我。我需要的只是转换。 提前感谢如果createdTs属性是日期对象,您可以使用 如果它是字符串类型,您可以在服务器端进行格式化。还记得像这样指定标记库uri <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-

我必须在jsp页面本身中格式化从控制器[Spring]收到的日期。
以下是JSP文件:

我是否可以以某种方式使用此函数,或者其他任何替代方法是否适用于我。我需要的只是转换。

提前感谢

如果createdTs属性是日期对象,您可以使用



如果它是字符串类型,您可以在服务器端进行格式化。

还记得像这样指定标记库uri
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<!DOCTYPE html>
<html lang="en">

<head>

<script
src="${pageContext.request.contextPath}/static/js/custom/customer.js">/script>
</head>
<body>

                <table id="success-story">
                    <thead>
                        <tr>
                            <th width="5%">Sl#</th>
                            <th width="50%">Description</th>
                            <th width="10%">Status</th>
                            <th width="30%">Created on</th>
                            <th width="5%">Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <c:forEach items="${customer.rfqs}" var="v" varStatus="count">
                            <tr>
                                <td>${count.count}</td>
                                <td>${v.description}</td>
                                <td>${v.status}</td>
                                <td>$v.createdTs</td>
                                <td align="center">
                                   <a href="#" onclick="view(${v.requestId})"> view</a>
                                   <a href="#" onclick="edit(${v.requestId})">edit</a>
                                </td>
                            </tr>
                        </c:forEach>
                    </tbody>
                </table>

  </body>
 </html>'
function formatDate(date) {
  var monthNames = [
    "Jan", "Feb", "Mar",
    "Apr", "May", "Jun", "Jul",
    "Aug", "Sep", "Oct",
    "Nov", "Dec"
  ];

  var day = date.getDate();
  var monthIndex = date.getMonth();
  var year = date.getFullYear();

  return day + ' ' + monthNames[monthIndex] + ' ' + year;
}
<fmt:formatDate pattern = "yyyy-MM-dd" value = "${v.createdTs}" />