我正在使用Servlet代码显示雷达图,但抛出了错误505,因此我该怎么办
我的鳕鱼是
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
import org.jfree.chart.plot.SpiderWebPlot;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.DefaultCategoryDataset;
/**
* Servlet implementation class chartexample
*/
public class chartexample extends HttpServlet {
private static final long serialVersionUID = 1L;
public DefaultCategoryDataset dataset;
public SpiderWebPlot plot;
/**
* Default constructor.
*/
public void service(HttpServletRequest request,HttpServletResponse response){
response.setContentType ("image / jpeg");
ServletOutputStream sos = null;
try {
sos = response.getOutputStream ();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String series1 = "First";
String series2 = "Second";
String series3 = "Third";
String category1 = "Task Completion";
String category2 = "Accuracy";
String category3 = "Sophistication";
String category4 = "Listening";
String category5 = "Pronunciation";
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(5.0, series1, category1);
dataset.addValue(5.0, series1, category2);
dataset.addValue(5.0, series1, category3);
dataset.addValue(5.0, series1, category4);
dataset.addValue(5.0, series1, category5);
dataset.addValue(2.0, series2, category1);
dataset.addValue(4.0, series2, category2);
dataset.addValue(5.0, series2, category3);
dataset.addValue(3.0, series2, category4);
dataset.addValue(5.0, series2, category5);
SpiderWebPlot plot = new SpiderWebPlot(dataset);
plot.setStartAngle(90);
plot.setInteriorGap(0.30);
plot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
JFreeChart chart = new JFreeChart("", TextTitle.DEFAULT_FONT, plot, false);
ChartUtilities.applyCurrentTheme(chart);
ChartRenderingInfo render = new ChartRenderingInfo();
response.setContentType ("image / jpeg");
try {
ChartUtilities.writeChartAsJPEG(sos, chart, 800, 800);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
错误是
javax.servlet.ServletException: Error instantiating servlet class chartexample
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.NoClassDefFoundError: org/jfree/data/category/CategoryDataset
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
java.lang.Class.getConstructor0(Unknown Source)
java.lang.Class.newInstance0(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.ClassNotFoundException: org.jfree.data.category.CategoryDataset
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
java.lang.Class.getConstructor0(Unknown Source)
java.lang.Class.newInstance0(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)
最佳答案
java.lang.ClassNotFoundException: org.jfree.data.category.CategoryDataset
运行时类路径中缺少JFreeChart JAR文件。将它们放在
/WEB-INF/lib
文件夹中。