我有一系列 JSP,每个 JSP 都包含一个 scriptlet,用于使用 Google 的图表工具生成可视化代码。这些在运行时动态调用以显示可视化。以下编辑的代码是典型的:
<-- HTML of JSP here -->
<script type = "text/javascript" src = "http://www.google.com/jsapi"></script>
<script type = "text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
out.println("data.addRows(" + pv.getNoRows() + ");");
function drawChart() {
var data = new google.visualization.DataTable();
<%
int row = 0;
List<List<String>> datasetVisData = pv.getDatasetVisData();
ArrayList<String> datasetVisTemporalAxisLabels = pv.getDatasetVisTemporalAxisLabels();
for (List<String> list : datasetVisualisationData) {
out.println("data.setValue(" + row + ", " + 0 + ", '" + datasetVisTemporalAxisLabels.get(row) + "');");
for (int column = 0; column < list.size() - 1; column++) {
out.println("data.setValue(" + row + ", " + (column + 1) + ", " + list.get(column) + ");");
}
row++;
}
%>
}
</script>
<-- HTML of JSP here -->
此 scriptlet 生成 Javascript,如下所示:
data.addRows(2);
data.setValue(0, 0, '22 06 2011 @ 10 00');
data.setValue(0, 1, 10);
data.setValue(0, 2, 10);
data.setValue(0, 3, 10);
data.setValue(0, 4, 15);
data.setValue(0, 5, 10);
data.setValue(1, 0, '22 06 2011 @ 12 00');
data.setValue(1, 1, 5);
data.setValue(1, 2, 4);
data.setValue(1, 3, 3);
data.setValue(1, 4, 2);
data.setValue(1, 5, 2);
依此类推,以便可以向 Google 发出请求以在运行时呈现可视化。
但是我的问题是上面的方向略有不同,即如果我想将上面的输出转移到可以存储在文件系统中的 .html 文件中,然后合并到稍后发出的 JSP 请求中怎么办?
谁能建议什么可能是一种有用的方法来做到这一点?目前我唯一能想到的就是在 Java 代码中生成 HTML 和嵌入的 Javascript 并将输出写入文本文件,例如
System.out.println("<p></form>\n" +
System.out.println("<p><input type = \"submit\" value = \"Plot options\"></form>\n" +
"</fieldset><p>\n<p> </p>");
System.out.println("<script language = \"javascript\">");
System.out.println("document.plotcriteria.reset();");
System.out.println("</script>");
任何人都可以提出更好的选择吗?是否可以将 JSP 的输出转移到文件系统而不是客户端浏览器?
谢谢
摩根先生。