目前,我有一个servlet,它可以转发给jsp。jsp可以访问会话属性"current“。在加载jsp期间,"current“中的信息将传递给生成图形的javascript函数。一切都很顺利。我唯一的问题是我很难对图形数据进行编码。
如何将数据数组从servlet传递给jsp。基本上,在creerRapport函数中,在第5个参数中,如何用java属性替换它?
任何帮助或想法都将不胜感激。
用硬编码的数据当前的代码.
<body onload="soumettreRapport();">
<script type="text/javascript">
function soumettreRapport() {
creerRapport( "${current.title}",
"${current.type}",
${current.width},
${current.height},
[
{
key: "Cumulative Return",
values: [
{
"label" : "2001" ,
"value" : -29.76
} ,
{
"label" : "2002" ,
"value" : 0
} ,
{
"label" : "2003 ,
"value" : 32.80
}
]
}
]
);
return false;
}发布于 2014-01-06 01:28:27
在Servlet中,需要将JSON数组作为字符串,然后将该字符串放入请求范围。
String jsonArrayString = convert(...); // Output [{key:"Cumulative Return", .... }]
request.setAttribute("jsonArrayString", jsonArrayString);在JSP中:
function soumettreRapport() {
var jsonArray = ${jsonArrayString};
creerRapport( "${current.title}",
"${current.type}",
${current.width},
${current.height}, jsonArray );
}https://stackoverflow.com/questions/20940884
复制相似问题