嗨我有数据库表job_status有字段日期,时间和速度。我想在jsp页面上显示速度和时间之间的图表,但我收到错误,所以在这里发布问题。请帮助我
<%// required packages %>
<%@ page import ="DB.*" %>
<%@ page import="java.awt.Image" %>
<%@ page import="java.awt.*"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="java.awt.BasicStroke"%>
<%@ page import ="org.jfree.ui.ApplicationFrame"%>
<%@ page import="java.io.*" %>
<%@ page import="java.io.File"%>
<%@ page import="org.jfree.chart.*" %>
<%@ page import="org.jfree.chart.axis.*" %>
<%@ page import="org.jfree.chart.entity.*" %>
<%@ page import="org.jfree.chart.labels.*" %>
<%@ page import="org.jfree.chart.plot.*" %>
<%@ page import="org.jfree.chart.renderer.category.*" %>
<%@ page import="org.jfree.chart.urls.*" %>
<%@ page import="org.jfree.data.category.*" %>
<%@ page import="org.jfree.data.general.*" %>
<%@ page import="org.jfree.data.time.Minute"%>
<%@ page import="org.jfree.data.time.Hour"%>
<%@ page import="org.jfree.data.time.TimeSeries"%>
<%@ page import="org.jfree.data.time.TimeSeriesCollection"%>
<%@ page import="org.jfree.data.xy.XYDataset"%>
<%@ page import="org.jfree.chart.plot.XYPlot"%>
<%@ page import="org.jfree.chart.renderer.xy.StandardXYItemRenderer"%>
<%@ page import="org.jfree.chart.renderer.xy.XYItemRenderer"%>
<%@ page import= "java.sql.Connection" %>
<%@ page import ="java.sql.DriverManager" %>
<%@ page import = "java.sql.SQLException" %>
<%@ page import = "java.sql.PreparedStatement" %>
<%@ page import = "java.sql.ResultSet" %>
<%@ page import = "java.sql.Statement" %>
<%@ page import= "javax.servlet.*" %>
<%@ page import ="javax.servlet.http.*" %>
<%@ page import="java.awt.image.BufferedImage"%>
<%
try
{
File image = File.createTempFile("image", "tmp");
//chart class instance
Fms fm = new Fms("Graph");
JFreeChart chart = fm.createChart(fm.dataset);
ChartUtilities.saveChartAsPNG(image, chart, 500, 400);
//get input stream
FileInputStream fileInStream = new FileInputStream(image);
//output stream foe returning chart as image
OutputStream outStream = response.getOutputStream();
long fileLength;
byte[] byteStream;
fileLength = image.length();
byteStream = new byte[(int)fileLength];
//read chart image
fileInStream.read(byteStream, 0, (int)fileLength);
//returns chart image whenever called
response.setContentType("image/png");
response.setContentLength((int)fileLength);
response.setHeader("Cache-Control","no-store,no-cache, must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "no-cache");
fileInStream.close();
outStream.write(byteStream);
outStream.flush();
outStream.close();
}
catch (IOException e)
{
System.err.println("Problem occurred creating chart.");
}
%>
<%! public class Fms extends ApplicationFrame {
//Main class
XYDataset dataset= null;
public Fms(final String title) {
super(title);
dataset= createDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(700, 570));
chartPanel.setMouseZoomable(true, false);
setContentPane(chartPanel);
}
//chart creation method
JFreeChart createChart(final XYDataset dataset) {
final JFreeChart chart = ChartFactory.createTimeSeriesChart(
"Speed Chart",
"Time",
"Speed",
dataset,
true,
true,
false
);
chart.setBackgroundPaint(Color.white);
final XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(false);
final XYItemRenderer renderer = plot.getRenderer();
if (renderer instanceof StandardXYItemRenderer) {
final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
rr.setShapesFilled(true);
renderer.setSeriesStroke(0, new BasicStroke(1.0f));
renderer.setSeriesStroke(1, new BasicStroke(1.0f));
}
final DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("dd:MM"));
try{
final ChartRenderingInfo info = new ChartRenderingInfo
(new StandardEntityCollection());
final File file1 = new File("/barchart.png");
ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
}catch(Exception e){}
return chart;
}
//data set generation method
private XYDataset createDataset() {
final TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.setDomainIsPointsInTime(true);
final TimeSeries s1 = new TimeSeries("Series 1", Minute.class);
int str = 0;
int i =0,j= 0 ;
String str1 = null;
try{
DataBaseConnection db= new DataBaseConnection();
Connection con=db.connet();
PreparedStatement st;
Statement stmt = con.createStatement();
String query = "Select * from Job_Status";
stmt.executeQuery(query);
ResultSet rs = stmt.executeQuery(query);
while( rs.next() )
{
str1= rs.getString("Time");
String sa = str1.substring(11,13);
String ha = str1.substring(14,16);
str= rs.getInt("Speed");
j=Integer.parseInt(sa);
i=Integer.parseInt(ha);
String date = rs.getString("Date");
String y = date.substring(0,4);
String m = date.substring(5,7);
String d = date.substring(8,10);
s1.add(new Minute(i, j, Integer.parseInt(d), Integer.parseInt(m), Integer.parseInt(y)), str);
}
}
catch(Exception e)
{
}
System.out.println(str1.substring(11,13));
System.out.println(str1.substring(14,16)+"\t"+str1);
dataset.addSeries(s1);
return dataset;
}
}
%>
错误是
HTTP Status 500 - Unable to compile class for JSP:
type Exception report
message Unable to compile class for JSP:
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: [19] in the generated java file: [/home/sukanth/workspace1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/project1/org/apache/jsp/chart_jsp.java]
Only a type can be imported. org.jfree.ui.ApplicationFrame resolves to a package
An error occurred at line: [31] in the generated java file: [/home/sukanth/workspace1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/project1/org/apache/jsp/chart_jsp.java]
Only a type can be imported. org.jfree.data.time.Minute resolves to a package
An error occurred at line: [32] in the generated java file: [/home/sukanth/workspace1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/project1/org/apache/jsp/chart_jsp.java]
Only a type can be imported. org.jfree.data.time.Hour resolves to a package
An error occurred at line: [33] in the generated java file: [/home/sukanth/workspace1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/project1/org/apache/jsp/chart_jsp.java]
Only a type can be imported. org.jfree.data.time.TimeSeries resolves to a package
An error occurred at line: [34] in the generated java file: [/home/sukanth/workspace1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/project1/org/apache/jsp/chart_jsp.java]
Only a type can be imported. org.jfree.data.time.TimeSeriesCollection resolves to a package
An error occurred at line: [35] in the generated java file: [/home/sukanth/workspace1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/project1/org/apache/jsp/chart_jsp.java]
Only a type can be imported. org.jfree.data.xy.XYDataset resolves to a package
An error occurred at line: [36] in the generated java file: [/home/sukanth/workspace1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/project1/org/apache/jsp/chart_jsp.java]
Only a type can be imported. org.jfree.chart.plot.XYPlot resolves to a package
An error occurred at line: [37] in the generated java file: [/home/sukanth/workspace1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/project1/org/apache/jsp/chart_jsp.java]
Only a type can be imported. org.jfree.chart.renderer.xy.StandardXYItemRenderer resolves to a package
An error occurred at line: [38] in the generated java file: [/home/sukanth/workspace1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/project1/org/apache/jsp/chart_jsp.java]
Only a type can be imported. org.jfree.chart.renderer.xy.XYItemRenderer resolves to a package
An error occurred at line: 73 in the jsp file: /chart.jsp
ApplicationFrame cannot be resolved to a type
70: System.err.println("Problem occurred creating chart.");
71: }
72: %>
73: <%! public class Fms extends ApplicationFrame {
74: //Main class
75: XYDataset dataset= null;
76: public Fms(final String title) {
An error occurred at line: 75 in the jsp file: /chart.jsp
XYDataset cannot be resolved to a type
72: %>
73: <%! public class Fms extends ApplicationFrame {
74: //Main class
75: XYDataset dataset= null;
76: public Fms(final String title) {
77: super(title);
78: dataset= createDataset();
An error occurred at line: 78 in the jsp file: /chart.jsp
dataset cannot be resolved to a variable
75: XYDataset dataset= null;
76: public Fms(final String title) {
77: super(title);
78: dataset= createDataset();
79: final JFreeChart chart = createChart(dataset);
80: final ChartPanel chartPanel = new ChartPanel(chart);
81: chartPanel.setPreferredSize(new java.awt.Dimension(700, 570));
An error occurred at line: 78 in the jsp file: /chart.jsp
The method createDataset() is undefined for the type chart_jsp.Fms
75: XYDataset dataset= null;
76: public Fms(final String title) {
77: super(title);
78: dataset= createDataset();
79: final JFreeChart chart = createChart(dataset);
80: final ChartPanel chartPanel = new ChartPanel(chart);
81: chartPanel.setPreferredSize(new java.awt.Dimension(700, 570));
An error occurred at line: 79 in the jsp file: /chart.jsp
JFreeChart cannot be resolved to a type
76: public Fms(final String title) {
77: super(title);
78: dataset= createDataset();
79: final JFreeChart chart = createChart(dataset);
80: final ChartPanel chartPanel = new ChartPanel(chart);
81: chartPanel.setPreferredSize(new java.awt.Dimension(700, 570));
82: chartPanel.setMouseZoomable(true, false);
An error occurred at line: 79 in the jsp file: /chart.jsp
dataset cannot be resolved to a variable
76: public Fms(final String title) {
77: super(title);
78: dataset= createDataset();
79: final JFreeChart chart = createChart(dataset);
80: final ChartPanel chartPanel = new ChartPanel(chart);
81: chartPanel.setPreferredSize(new java.awt.Dimension(700, 570));
82: chartPanel.setMouseZoomable(true, false);
An error occurred at line: 80 in the jsp file: /chart.jsp
ChartPanel cannot be resolved to a type
77: super(title);
78: dataset= createDataset();
79: final JFreeChart chart = createChart(dataset);
80: final ChartPanel chartPanel = new ChartPanel(chart);
81: chartPanel.setPreferredSize(new java.awt.Dimension(700, 570));
82: chartPanel.setMouseZoomable(true, false);
83: setContentPane(chartPanel);
An error occurred at line: 80 in the jsp file: /chart.jsp
ChartPanel cannot be resolved to a type
77: super(title);
78: dataset= createDataset();
79: final JFreeChart chart = createChart(dataset);
80: final ChartPanel chartPanel = new ChartPanel(chart);
81: chartPanel.setPreferredSize(new java.awt.Dimension(700, 570));
82: chartPanel.setMouseZoomable(true, false);
83: setContentPane(chartPanel);
An error occurred at line: 86 in the jsp file: /chart.jsp
JFreeChart cannot be resolved to a type
83: setContentPane(chartPanel);
84: }
85: //chart creation method
86: JFreeChart createChart(final XYDataset dataset) {
87: final JFreeChart chart = ChartFactory.createTimeSeriesChart(
88: "Speed Chart",
89: "Time",
An error occurred at line: 86 in the jsp file: /chart.jsp
XYDataset cannot be resolved to a type
83: setContentPane(chartPanel);
84: }
85: //chart creation method
86: JFreeChart createChart(final XYDataset dataset) {
87: final JFreeChart chart = ChartFactory.createTimeSeriesChart(
88: "Speed Chart",
89: "Time",
An error occurred at line: 87 in the jsp file: /chart.jsp
JFreeChart cannot be resolved to a type
84: }
85: //chart creation method
86: JFreeChart createChart(final XYDataset dataset) {
87: final JFreeChart chart = ChartFactory.createTimeSeriesChart(
88: "Speed Chart",
89: "Time",
90: "Speed",
An error occurred at line: 87 in the jsp file: /chart.jsp
ChartFactory cannot be resolved
84: }
85: //chart creation method
86: JFreeChart createChart(final XYDataset dataset) {
87: final JFreeChart chart = ChartFactory.createTimeSeriesChart(
88: "Speed Chart",
89: "Time",
90: "Speed",
An error occurred at line: 97 in the jsp file: /chart.jsp
XYPlot cannot be resolved to a type
94: false
95: );
96: chart.setBackgroundPaint(Color.white);
97: final XYPlot plot = chart.getXYPlot();
98: plot.setBackgroundPaint(Color.lightGray);
99: plot.setDomainGridlinePaint(Color.white);
100: plot.setRangeGridlinePaint(Color.white);
An error occurred at line: 103 in the jsp file: /chart.jsp
XYItemRenderer cannot be resolved to a type
100: plot.setRangeGridlinePaint(Color.white);
101: plot.setDomainCrosshairVisible(true);
102: plot.setRangeCrosshairVisible(false);
103: final XYItemRenderer renderer = plot.getRenderer();
104: if (renderer instanceof StandardXYItemRenderer) {
105: final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
106: rr.setShapesFilled(true);
An error occurred at line: 104 in the jsp file: /chart.jsp
StandardXYItemRenderer cannot be resolved to a type
101: plot.setDomainCrosshairVisible(true);
102: plot.setRangeCrosshairVisible(false);
103: final XYItemRenderer renderer = plot.getRenderer();
104: if (renderer instanceof StandardXYItemRenderer) {
105: final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
106: rr.setShapesFilled(true);
107: renderer.setSeriesStroke(0, new BasicStroke(1.0f));
An error occurred at line: 105 in the jsp file: /chart.jsp
StandardXYItemRenderer cannot be resolved to a type
102: plot.setRangeCrosshairVisible(false);
103: final XYItemRenderer renderer = plot.getRenderer();
104: if (renderer instanceof StandardXYItemRenderer) {
105: final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
106: rr.setShapesFilled(true);
107: renderer.setSeriesStroke(0, new BasicStroke(1.0f));
108: renderer.setSeriesStroke(1, new BasicStroke(1.0f));
An error occurred at line: 105 in the jsp file: /chart.jsp
StandardXYItemRenderer cannot be resolved to a type
102: plot.setRangeCrosshairVisible(false);
103: final XYItemRenderer renderer = plot.getRenderer();
104: if (renderer instanceof StandardXYItemRenderer) {
105: final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
106: rr.setShapesFilled(true);
107: renderer.setSeriesStroke(0, new BasicStroke(1.0f));
108: renderer.setSeriesStroke(1, new BasicStroke(1.0f));
An error occurred at line: 110 in the jsp file: /chart.jsp
DateAxis cannot be resolved to a type
107: renderer.setSeriesStroke(0, new BasicStroke(1.0f));
108: renderer.setSeriesStroke(1, new BasicStroke(1.0f));
109: }
110: final DateAxis axis = (DateAxis) plot.getDomainAxis();
111: axis.setDateFormatOverride(new SimpleDateFormat("dd:MM"));
112: try{
113: final ChartRenderingInfo info = new ChartRenderingInfo
An error occurred at line: 110 in the jsp file: /chart.jsp
DateAxis cannot be resolved to a type
107: renderer.setSeriesStroke(0, new BasicStroke(1.0f));
108: renderer.setSeriesStroke(1, new BasicStroke(1.0f));
109: }
110: final DateAxis axis = (DateAxis) plot.getDomainAxis();
111: axis.setDateFormatOverride(new SimpleDateFormat("dd:MM"));
112: try{
113: final ChartRenderingInfo info = new ChartRenderingInfo
An error occurred at line: 113 in the jsp file: /chart.jsp
ChartRenderingInfo cannot be resolved to a type
110: final DateAxis axis = (DateAxis) plot.getDomainAxis();
111: axis.setDateFormatOverride(new SimpleDateFormat("dd:MM"));
112: try{
113: final ChartRenderingInfo info = new ChartRenderingInfo
114: (new StandardEntityCollection());
115: final File file1 = new File("/barchart.png");
116: ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
An error occurred at line: 113 in the jsp file: /chart.jsp
ChartRenderingInfo cannot be resolved to a type
110: final DateAxis axis = (DateAxis) plot.getDomainAxis();
111: axis.setDateFormatOverride(new SimpleDateFormat("dd:MM"));
112: try{
113: final ChartRenderingInfo info = new ChartRenderingInfo
114: (new StandardEntityCollection());
115: final File file1 = new File("/barchart.png");
116: ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
An error occurred at line: 114 in the jsp file: /chart.jsp
StandardEntityCollection cannot be resolved to a type
111: axis.setDateFormatOverride(new SimpleDateFormat("dd:MM"));
112: try{
113: final ChartRenderingInfo info = new ChartRenderingInfo
114: (new StandardEntityCollection());
115: final File file1 = new File("/barchart.png");
116: ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
117: }catch(Exception e){}
An error occurred at line: 116 in the jsp file: /chart.jsp
ChartUtilities cannot be resolved
113: final ChartRenderingInfo info = new ChartRenderingInfo
114: (new StandardEntityCollection());
115: final File file1 = new File("/barchart.png");
116: ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
117: }catch(Exception e){}
118: return chart;
119: }
An error occurred at line: 121 in the jsp file: /chart.jsp
XYDataset cannot be resolved to a type
118: return chart;
119: }
120: //data set generation method
121: private XYDataset createDataset() {
122: final TimeSeriesCollection dataset = new TimeSeriesCollection();
123: dataset.setDomainIsPointsInTime(true);
124: final TimeSeries s1 = new TimeSeries("Series 1", Minute.class);
An error occurred at line: 122 in the jsp file: /chart.jsp
TimeSeriesCollection cannot be resolved to a type
119: }
120: //data set generation method
121: private XYDataset createDataset() {
122: final TimeSeriesCollection dataset = new TimeSeriesCollection();
123: dataset.setDomainIsPointsInTime(true);
124: final TimeSeries s1 = new TimeSeries("Series 1", Minute.class);
125: int str = 0;
An error occurred at line: 122 in the jsp file: /chart.jsp
TimeSeriesCollection cannot be resolved to a type
119: }
120: //data set generation method
121: private XYDataset createDataset() {
122: final TimeSeriesCollection dataset = new TimeSeriesCollection();
123: dataset.setDomainIsPointsInTime(true);
124: final TimeSeries s1 = new TimeSeries("Series 1", Minute.class);
125: int str = 0;
An error occurred at line: 124 in the jsp file: /chart.jsp
TimeSeries cannot be resolved to a type
121: private XYDataset createDataset() {
122: final TimeSeriesCollection dataset = new TimeSeriesCollection();
123: dataset.setDomainIsPointsInTime(true);
124: final TimeSeries s1 = new TimeSeries("Series 1", Minute.class);
125: int str = 0;
126: int i =0,j= 0 ;
127: String str1 = null;
An error occurred at line: 124 in the jsp file: /chart.jsp
TimeSeries cannot be resolved to a type
121: private XYDataset createDataset() {
122: final TimeSeriesCollection dataset = new TimeSeriesCollection();
123: dataset.setDomainIsPointsInTime(true);
124: final TimeSeries s1 = new TimeSeries("Series 1", Minute.class);
125: int str = 0;
126: int i =0,j= 0 ;
127: String str1 = null;
An error occurred at line: 124 in the jsp file: /chart.jsp
Minute cannot be resolved to a type
121: private XYDataset createDataset() {
122: final TimeSeriesCollection dataset = new TimeSeriesCollection();
123: dataset.setDomainIsPointsInTime(true);
124: final TimeSeries s1 = new TimeSeries("Series 1", Minute.class);
125: int str = 0;
126: int i =0,j= 0 ;
127: String str1 = null;
An error occurred at line: 148 in the jsp file: /chart.jsp
Minute cannot be resolved to a type
145: String y = date.substring(0,4);
146: String m = date.substring(5,7);
147: String d = date.substring(8,10);
148: s1.add(new Minute(i, j, Integer.parseInt(d), Integer.parseInt(m), Integer.parseInt(y)), str);
149: }
150: }
151: catch(Exception e)
An error occurred at line: 46 in the jsp file: /chart.jsp
JFreeChart cannot be resolved to a type
43: //chart class instance
44: Fms fm = new Fms("Graph");
45:
46: JFreeChart chart = fm.createChart(fm.dataset);
47: ChartUtilities.saveChartAsPNG(image, chart, 500, 400);
48: //get input stream
49: FileInputStream fileInStream = new FileInputStream(image);
An error occurred at line: 46 in the jsp file: /chart.jsp
dataset cannot be resolved or is not a field
43: //chart class instance
44: Fms fm = new Fms("Graph");
45:
46: JFreeChart chart = fm.createChart(fm.dataset);
47: ChartUtilities.saveChartAsPNG(image, chart, 500, 400);
48: //get input stream
49: FileInputStream fileInStream = new FileInputStream(image);
An error occurred at line: 47 in the jsp file: /chart.jsp
ChartUtilities cannot be resolved
44: Fms fm = new Fms("Graph");
45:
46: JFreeChart chart = fm.createChart(fm.dataset);
47: ChartUtilities.saveChartAsPNG(image, chart, 500, 400);
48: //get input stream
49: FileInputStream fileInStream = new FileInputStream(image);
50: //output stream foe returning chart as image
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.37 logs.
Apache Tomcat/7.0.37
修改没有编译错误只有运行时错误
答案 0 :(得分:0)
请把它写成一个servlet。 您将获得多种好处,包括显示编译错误的IDE。
您声明“没有Compilations错误,只有运行时错误”,但错误是编译错误,在尝试编译jsp时发生。