This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes servlet chart generate problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "servlet chart generate problem" Watch "servlet chart generate problem" New topic
Author

servlet chart generate problem

nayan rami
Ranch Hand

Joined: Dec 28, 2010
Posts: 30

hello friends

when i am running my this servlet it will give me an error and not generating chart

i m using same code for generate radar chart it will work fine in swing

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
System.out.println("hi");
System.out.println(e1.toString());
e1.printStackTrace();
}


String series1 = "First";
String series2 = "Second";


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
System.out.println("charutilities");
System.out.println(e.toString());
e.printStackTrace();
}
}
}

_____________________________________________________--------------------
error
_______________________________________________________-------------------------------

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

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)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.29 logs.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.29
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Can you please edit your post and UseCodeTags? That way we can read it easier and help you out


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41068
    
  43
Which jar files do you have in the WEB-INF/lib directory? You need both JFreeChart and JCommon.


Ping & DNS - my free Android networking tools app
 
 
subject: servlet chart generate problem
 
Similar Threads
Displaying scalable vector graphics on ibm aix
Dollar Symbol at Vertical Bar in StackedBarChar in JFreeChart
problem using jfreechart
how to write dataset value in chart using CategoryItemRenderer
Generate RADAR chart in jsp