How to access Spring MVC model object in javascript file?

前端 未结 8 1078
南方客
南方客 2020-12-28 19:05

I am using spring 3 MVC and i have below classes.

External system would call my application using below URL:

http://somehost/root/param1/param2/param         


        
相关标签:
8条回答
  • 2020-12-28 19:35

    Here is an example of how i made a list object available for javascript:

    var listForJavascript = [];
    <c:forEach items="${MyListFromJava}" var="listItem">
      var arr = [];
    
      arr.push("<c:out value="${listItem.param1}" />");
      arr.push("<c:out value="${listItem.param2}" />");
    
      listForJavascript.push(arr);
    </c:forEach>
    
    0 讨论(0)
  • 2020-12-28 19:37

    Another solution could be using in JSP: <input type="hidden" id="jsonBom" value='${jsonBom}'/>

    and getting the value in Javascript with jQuery:

    var jsonBom = $('#jsonBom').val();

    0 讨论(0)
提交回复
热议问题