我有一个包含 Java 类对象的 ArrayList。我想将该列表传递给 javascript,并希望将对象中的数据填充到 jsp 中。 ArrayList存在于jsp中。每个类对象只包含2个参数值。类名是'Certificate',它包含'certId'和'certName'
jsp:
<%
ArrayList getAllCertificateNamewithId=new ArrayList();
getAllCertificateNamewithId=(ArrayList)mainMap.get("getAllCertificateNamewithIdMap");%>
<input type="button" width="16" height="16" onclick="fetchAndShow('<%=getAllCertificateNamewithId %>')" />
Javascript
function fetchAndShow(certObj){
//How to fetch the list's each object and cast to java class 'Certificate'
}
列表包含
[com.dto.Certificate@9b44a1, com.dto.Certificate@1b6b3ac]
最佳答案
这样想:您使用 Java + JSP 作为编写文本文件的一种方式,然后将其发送到用户的浏览器,而 JSP 是一种简单的模板机制。
从理论上讲,您可以实现自己的方法来将包含对象的列表序列化为字符串,然后在客户端实现一种机制以反序列化为您想要的任何数据结构。例如,您可以将 List 写成 JSON。
但现在我想问:你真的、真的、真的、真的需要这样做吗?向客户端公开任何类型的服务器证书是一个很大的禁忌。
关于javascript - 想要在 javascript 中传递包含类对象的 ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43139159/