accessing session variables in javascript inside jsp

前端 未结 3 1952
失恋的感觉
失恋的感觉 2020-12-30 13:56

I need to provide data for google APIs table... so I\'ll send it from servlet to JSP

but how can I access this data in \"googles\" javascript?

I\'ll provide

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-30 14:08

    since the ArrayList is having objects of Strings you can simply use split() method on the value of the array list. Something like as below;

    function showTable() {  
      <%
           Object obj = session.getAttribute("list");
           List list = null;
           if (obj != null) {
               list = (ArrayList) obj;
           } else list = new ArrayList();  %>
    var jsList = <%=list.toString()%>
    
    //remove [] from content
    jsList = jsList.replace("[","");
    jsList = jsList.replace("]","");
    

    //split the contents var splitContent = jsList.split(","); //an array of element

    for(var i=0;i

    }

    I hope this will help you solve this.

提交回复
热议问题