User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 422,902 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,303 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 944 | Replies: 6 | Solved
Reply
Join Date: Oct 2007
Posts: 16
Reputation: samarinder is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
samarinder samarinder is offline Offline
Newbie Poster

plz help me in displaying charts

  #1  
Jun 5th, 2008
I m getting problem in displaying charts and m not exactly able to find the problem


plz plz help me wher i m wrong plzzzzzzzzzzzzzzzzzzzzzzz
its very urgent............--------

---------------------
  1. package src;
  2.  
  3. import java.io.PrintWriter;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.ResultSet;
  7. import java.sql.Statement;
  8.  
  9. import javax.servlet.http.HttpSession;
  10.  
  11.  
  12. import org.jfree.chart.ChartFactory;
  13. import org.jfree.chart.ChartRenderingInfo;
  14. import org.jfree.chart.ChartUtilities;
  15. import org.jfree.chart.JFreeChart;
  16.  
  17.  
  18. import org.jfree.chart.entity.StandardEntityCollection;
  19. import org.jfree.chart.plot.PlotOrientation;
  20. import org.jfree.chart.servlet.ServletUtilities;
  21.  
  22. import org.jfree.data.XYDataset;
  23. import org.jfree.data.XYSeries;
  24. import org.jfree.data.XYSeriesCollection;
  25.  
  26.  
  27.  
  28. public class WebHitChart {
  29. public static String generateXYChart(HttpSession session,
  30. PrintWriter pw) {
  31. String filename = null;
  32.  
  33. try {
  34. final String query = "select target_milestone,dre from dre_cal where product='WEBSITES' ";
  35. Connection conn;
  36.  
  37. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  38. conn = DriverManager.getConnection("jdbc:odbc:dreDSN");
  39. Statement statement = conn.createStatement();
  40. System.out.println("the value of conn ...." + conn);
  41. System.out.println("start");
  42. ResultSet rs = statement.executeQuery(query);
  43. XYSeries series = new XYSeries("Average Weight");
  44. while (rs.next()) {
  45. series.add(rs.getInt(1), rs.getInt(2));
  46. }
  47.  
  48. XYDataset xyDataset = (XYDataset) new XYSeriesCollection(series);
  49. JFreeChart chart = ChartFactory.createXYLineChart(
  50. "XYLine Chart using JFreeChart", "Age", "Weight",
  51. xyDataset, PlotOrientation.VERTICAL, true, true, false);
  52.  
  53. ChartRenderingInfo info = new ChartRenderingInfo(
  54. new StandardEntityCollection());
  55. filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info,
  56. session);
  57.  
  58. // Write the image map to the PrintWriter
  59. ChartUtilities.writeImageMap(pw, filename, info, false);
  60. pw.flush();
  61.  
  62. } catch (Exception e) {
  63. System.out.println("Exception - " + e.toString());
  64. e.printStackTrace(System.out);
  65. filename = "public_error_500x300.png";
  66. }
  67. return filename;
  68. }
------------------------------------------------------


  1. <%@ page import = "src.*" %>
  2. <%@ page import = "java.io.PrintWriter" %>
  3. <%
  4. String filename = WebHitChart.generateXYChart(session, new PrintWriter(out));
  5. String graphURL = request.getContextPath() + "/WebHitChart.do?filename=" + filename;
  6. %>
  7. <html>
  8. <body>
  9. <img src="<%= graphURL %>" width=500 height=300 border=0 usemap="#<%= filename %>">
  10. </body>
  11. </html>
------------------------------------------------------------
  1. <servlet>
  2. <servlet-name>somename</servlet-name>
  3. <servlet-class>src.WebHitChart</servlet-class>
  4. </servlet>
  5. <servlet-mapping>
  6. <servlet-name>somename</servlet-name>
  7. <url-pattern>/WebHitChart.do</url-pattern>
  8. </servlet-mapping>
---------------------------------

Error i m getting on jsp page is

HTTP Status 500 -

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

type Exception report

message 

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

exception 

org.apache.jasper.JasperException: An exception occurred processing JSP page /xy_area.jsp at line 4

1: <%@ page import = "src.*" %>
2: <%@ page import = "java.io.PrintWriter" %>
3: <%                  
4:      String filename = WebHitChart.generateXYChart(session, new PrintWriter(out));
5: 	String graphURL = request.getContextPath() + "/WebHitChart.do?filename=" + filename;
6: %>
7: <html>


Stacktrace:
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause 

javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/jfree/data/XYDataset
	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
	org.apache.jsp.xy_005farea_jsp._jspService(xy_005farea_jsp.java:76)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause 

java.lang.NoClassDefFoundError: org/jfree/data/XYDataset
	org.apache.jsp.xy_005farea_jsp._jspService(xy_005farea_jsp.java:58)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


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


--------------------------------------------------------------------------------
Last edited by peter_budo : Jun 6th, 2008 at 5:13 am. Reason: Keep It Organized - please use [code] tags + no need for usin bold on the text
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Posts: 16
Reputation: samarinder is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
samarinder samarinder is offline Offline
Newbie Poster

Re: plz help me in displaying charts

  #2  
Jun 5th, 2008
plzz help me...........
Reply With Quote  
Join Date: Oct 2007
Posts: 16
Reputation: samarinder is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
samarinder samarinder is offline Offline
Newbie Poster

Re: plz help me in displaying charts

  #3  
Jun 5th, 2008
i have tried with this way also still getting plz see the code
  1. package src;
  2.  
  3. import java.awt.image.BufferedImage;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9.  
  10. import javax.servlet.http.HttpServletRequest;
  11. import javax.servlet.http.HttpServletResponse;
  12. import javax.servlet.http.HttpSession;
  13.  
  14. import org.jfree.chart.ChartFactory;
  15. import org.jfree.chart.ChartRenderingInfo;
  16. import org.jfree.chart.JFreeChart;
  17. import org.jfree.chart.entity.StandardEntityCollection;
  18. import org.jfree.chart.plot.PlotOrientation;
  19. import org.jfree.data.XYDataset;
  20. import org.jfree.data.XYSeries;
  21. import org.jfree.data.XYSeriesCollection;
  22.  
  23. public class XYChartExample2 {
  24.  
  25.  
  26. public XYChartExample2() {
  27. }
  28.  
  29. public String getChartViewer(HttpServletRequest request,
  30. HttpServletResponse response) {
  31.  
  32. final String query = "select target_milestone,dre from dre_cal where product='WEBSITES' ";
  33. Connection conn;
  34.  
  35. try {
  36. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  37. conn = DriverManager.getConnection("jdbc:odbc:dreDSN");
  38. Statement statement = conn.createStatement();
  39. System.out.println("the value of conn ...." + conn);
  40. System.out.println("start");
  41. ResultSet rs = statement.executeQuery(query);
  42. XYSeries series = new XYSeries("Average Weight");
  43. while (rs.next()) {
  44. series.add(rs.getInt(1), rs.getInt(2));
  45. }
  46.  
  47. XYDataset xyDataset = (XYDataset) new XYSeriesCollection(series);
  48. JFreeChart chart = ChartFactory.createXYLineChart(
  49. "XYLine Chart using JFreeChart", "Age", "Weight",
  50. xyDataset, PlotOrientation.VERTICAL, true, true, false);
  51.  
  52. ChartRenderingInfo info = null;
  53. HttpSession session = request.getSession();
  54.  
  55. response.setContentType("text/html");
  56. info = new ChartRenderingInfo(new StandardEntityCollection());
  57. BufferedImage chartImage = chart.createBufferedImage(550, 350,
  58. info);
  59. session.setAttribute("chartImage", chartImage);
  60. // Write the image map to the PrintWriter
  61. } catch (ClassNotFoundException e) {
  62. // TODO Auto-generated catch block
  63. e.printStackTrace();
  64. } catch (SQLException e) {
  65. // TODO Auto-generated catch block
  66. e.printStackTrace();
  67. }
  68.  
  69. String pathInfo = "http://";
  70. pathInfo += request.getServerName();
  71. int port = request.getServerPort();
  72. pathInfo += ":" + String.valueOf(port);
  73. pathInfo += request.getContextPath();
  74. String chartViewer = pathInfo + "/servlet/ChartViewer";
  75. return chartViewer;
  76. }
  77. }
-----------------------------

  1. <%@ page import = "src.XYChartExample2" %>
  2. <%String chartViewer = XYChartExample2.g--);%>
  3. <html>
  4. <body>
  5. <img src="<%=chartViewer%>" border=0 usemap="#imageMap">
  6. </body>
  7. </html>


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

error m getting

type Exception report

message 

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: 2 in the jsp file: /xytest.jsp
Cannot make a static reference to the non-static method getChartViewer(HttpServletRequest, HttpServletResponse) from the type XYChartExample2
1: <%@ page import = "src.XYChartExample2" %>
2: <%String chartViewer = XYChartExample2.getChartViewer(request, response);%> 
3: <html>
4: <body>
5:  <img src="<%=chartViewer%>" border=0 usemap="#imageMap"> 


Stacktrace:
	org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
	org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
	org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
Last edited by peter_budo : Jun 6th, 2008 at 5:15 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Oct 2007
Posts: 16
Reputation: samarinder is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
samarinder samarinder is offline Offline
Newbie Poster

Re: plz help me in displaying charts

  #4  
Jun 5th, 2008
Hey check this out plz or tell me wat else i have to do ..........

Thanks
Sam
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,851
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 344
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: plz help me in displaying charts

  #5  
Jun 5th, 2008
The error message "Cannot make a static reference to the non-static method" says it all. You need to first instantiate the XYChartExample2 class before invoking its method. BTW, scriptlets are bad and knowing the basics of Java helps before jumping into J2EE.
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 197
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: plz help me in displaying charts

  #6  
Jun 5th, 2008
and it seems the kid also misses a basic understanding of classpaths, server configuration, and a lot of other things quite apart from not knowing Java and having the terribly bad idea of using scriptlets.

And it gets worse. The kid creates the chart (or tries to) as a file and then tries to do something unmentionable with it (at least the kid doesn't mention what it does with it, so I assume it's unmentionable).
Far easier to create a servlet that streams the chart and call that from an <img> tag.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Join Date: Oct 2007
Posts: 16
Reputation: samarinder is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
samarinder samarinder is offline Offline
Newbie Poster

Re: plz help me in displaying charts

  #7  
Jun 6th, 2008
Thanks boss.......
I m able to display the graph now......
but i have to work hard to make me conformtable with java ...........

ur suggestions make a worth for me, thanks for spending time on my issues.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JSP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the JSP Forum

All times are GMT -4. The time now is 1:15 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC