您好,我是 Web 开发和 Java 的新手,提前感谢您的帮助。
我正在尝试将 servlet 中的预定义数据获取到 jsp 中的 canvasjs 图中。
我使用 Eclipse Oxygen 和 TomCat 8.5
简而言之,我的代码如下所示:
ChartValues.java 只有变量实例化,所以我认为不值得展示
jsp 文件:
<%@page import="saagnik.ChartValues"%>
<%@page import="java.util.ArrayList"%>
<%@page session="true" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript"src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<script type="text/javascript">
window.onload = function() {
var datapoints=[];
var chart = new CanvasJS.Chart("chartContainer1",{
title:{
text: "Anzahl der Requests"
},
data: [{
type: "splineArea",
name: "Anzahl",
dataPoints: datapoints
}]
});
String test=(String)session.getAttribute("test1");
datapoints.push({x: new Date(2015, 03, 10), y: 10});
chart.render();
</script>
</header>
<body>
<div id="chartContainer1"></div>
</body>
</html>
当我评论会话行时,程序工作正常,但是当包含它时,图表将无法构建。
Servlet 文件:
package saagnik;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet("/ChartServlet")
public class ChartServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
牛魔王的故事
相关分类