how to generate a bar chart on a JSP PAGE using the arraylist object passed form the servlet.(using jfreechart)

how to generate a bar chart on a JSP PAGE using the arraylist object passed form the servlet.(using jfreechart)

I have created a servlet.In this,i have retrieved a record from MS Access database in an arraylist i.e. my arraylist contains only one object(rollno,name,marks1,marks2,marks3,marks4) from the database.now i have to pass this arraylist object to a jsp page and on that jsp page i have to display a graph between a student semester-marks .(semesters on x-axis and marks1,marks2,marks3,marks4 on y-axis) using JFREECHART.how can i do it.please reply soon.I am attaching my servlet and jsp page beneath. please reply asap.Its urgent.

Here is my code:

arraylist.java(servlet)

import java.util.ArrayList;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author AARUSHI
 */
class database
 {
     int roll;
  String name;
  int marks1;
   int marks2;
    int marks3;
     int marks4;
  public database(int r,String nm,int m1,int m2,int m3,int m4)
   {

      roll=r;
      name=nm;
      marks1=m1;
      marks2=m2;
      marks3=m3;
      marks4=m4;
   }
    @Override
  public String toString()
   {
      return roll + ":" + name + ":" + marks1 + ":" + marks2 + ":" + marks3 + ":" + marks4;
   }
}
public class arraylist extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        ArrayList<database> v = new ArrayList<database>();
        database db;

        try {
             int rollno=Integer.parseInt(request.getParameter("txtroll"));

           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:cdotdsn");

    PreparedStatement ps=con.prepareStatement("select * from cdottable where rollno=?");
        ps.setString(1,""+rollno);
        ResultSet rs=ps.executeQuery();
        out.println("hello1");

        while(rs.next())
        {
           //  out.println("1st "+rs.getString(1));
         // out.println("2nd "+rs.getString(2));
        //out.println("3rd "+rs.getString(3));
      //out.println("4th "+rs.getString(4));
         //  out.println("5th "+rs.getString(5));
         //  out.println("6th "+rs.getString(6));
      int r=Integer.parseInt(rs.getString(1));
       String nm=rs.getString(2);
       int m1=Integer.parseInt(rs.getString(3));
       int m2=Integer.parseInt(rs.getString(4));
       int m3=Integer.parseInt(rs.getString(5));
       int m4=Integer.parseInt(rs.getString(6));
       out.println(r+ nm + m1 + m2 + m3 + m4);
       out.println("abc");
       db=new database(r,nm,m1,m2,m3,m4);
        v.add(db);
       int m=v.size();
         out.println(m);
       out.println( v );
        }
       for (int i=0;i<v.size();i++)
{
//out.println("<tr><td><br>name======" + rowArray.get(i) + "</td></tr>");
request.getSession().setAttribute("myArrayList",v);
RequestDispatcher requestDispatcher=getServletContext().getRequestDispatcher("/myjsp.jsp");
requestDispatcher.forward(request,response);
}


        con.close();
        }
  catch(Exception e)
        {
           out.println(e);
        }

    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}

Jsp page(myjsp.jsp)

<%-- 
    Document   : myjsp
    Created on : Oct 19, 2011, 8:22:50 PM
    Author     : AARUSHI
--%>

<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%@page import="java.util.ArrayList"%>
<%@ page session="true"%>
<%@page import="java.io.*"%>
<%@page import="javax.servlet.*"%>
<%@page import="java.io.*"%>
<%@page import="p1.*"%>



<%@page contentType="text/html" 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">
        <title>JSP Page</title>
    </head>
    <body>


<%
try
{

ArrayList pageArray = new ArrayList();
pageArray.add(request.getSession().getAttribute("myArrayList"));
//pageArray.add(request.getAttribute("myArrayList")) ;
for (int i=0;i<pageArray.size();i++)
{
out.println(pageArray.get(i));
}
out.println(pageArray.size());
}
catch(Exception e)
{
out.println(e);
e.printStackTrace();
}
%>


    </body>
</html>

my access database contains the follwing fields(rollno,name,marks1,2,3,4). Please answer my query soon.

View Answers

October 20, 2011 at 11:27 AM


October 20, 2011 at 11:56 AM

thankyou for the code.But this is not wat i m asking.tellme how can I generate the bar graph in my code attached i.e. myjsp.jsp.

I have sent the data from servlet to jsp already.









Related Tutorials/Questions & Answers:
how to generate a bar chart on a JSP PAGE using the arraylist object passed form the servlet.(using jfreechart)
how to generate a bar chart on a JSP PAGE using the arraylist object passed form the servlet.(using jfreechart)  I have created a servlet.In this,i... the database.now i have to pass this arraylist object to a jsp page and on that jsp page
Create a bar chart in JSP page using JFreeChart
Create a bar chart in JSP page using JFreeChart       This Example shows you how to create a bar chart in JSP page using JFreeChart. Code given below creates a bar chart
Advertisements
Create a 3D bar chart in JSP page using JFreeChart
Create a 3D bar chart in JSP page using JFreeChart       This Example shows you how to create a 3D bar chart in jsp page using JFreeChart. Code given below creates a bar
Create a pie chart in jsp page using JFreeChart
Create a pie chart in jsp page using JFreeChart... to create a pie chart in jsp page using JFreeChart. Code given below creates... is used to create bar chart for given values. It takes title, category axis label
Bar Chart using JSP and tooltip to be implemented
Bar Chart using JSP and tooltip to be implemented  Hi Deepak, I have generated a bar chart in JSP using JFreeCharts but I could not get the tool tip for that. Please any one suggest me how to do that or provide some code. Help
Stacked Bar Chart using JFreeChart
Stacked Bar Chart using JFreeChart   ... bar chart using JFreeChart. In the code given below we have extended class.... createStackedBarChart(): This method is used to create stacked bar chart for given values
how to create bar chart in jsp using msaccess database
how to create bar chart in jsp using msaccess database  type...\Tomcat 5.0\work\Catalina\localhost\chetana\org\apache\jsp\bar_jsp.java:61: cannot...: Unable to compile class for JSP An error occurred at line: 10 in the jsp file
Create area chart in JSP page using JFreeChart
Create area chart in JSP page using JFreeChart... to create a area chart in JSP page using JFreeChart. Code given below creates a area...(): This method is used to create bar chart for given values. It takes title
generate charts using JSP
generate charts using JSP  any one know coding for generate bar chart or pie chart using JSP
Bar Chart in JSP - JSP-Servlet
Bar Chart in JSP  Hi I am creating Bar chart using Jfree charts in JSP. Please advise me how to customize it. Like controlling the colors, width for each bar, showing values above the bar .  hi friend, Use
create bar chart in jsp using msaccess database
create bar chart in jsp using msaccess database  thanks for reply...) org.apache.jsp.bar<em>jsp.</em>jspService(bar_jsp.java:57...({}); 6) Restart your server and run given jsp code. <%@ page import
Stacked Bar Chart Example using JFreeChart
Stacked Bar Chart Example using JFreeChart... a Stacked bar chart using JFreeChart. Bar chart will represent scores of two team... to create stacked bar chart for given values. It  takes title, domain axis
create bar chart in jsp using msaccess database
create bar chart in jsp using msaccess database  type Exception...\work\Catalina\localhost\chetana\org\apache\jsp\bar_jsp.java:57: cannot find symbol... to compile class for JSP An error occurred at line: 8 in the jsp file: /bar.jsp
How to create bar chart using database values
How to create bar chart using database values  How to create bar chart using database values i.e excellent,good,average fields using jsp?It is like opinion poll.I want to show how many votes are came for excellent,good,average
Stacked 3d Bar Chart Example using JFreeChart
Stacked 3d Bar Chart Example using JFreeChart... a Stacked 3d bar chart using JFreeChart. Bar chart will represent the score...(): This method is used to create stacked bar chart for given values. It takes
How to generate the pdf file using jsp - JSP-Servlet
How to generate the pdf file using jsp  Hi how to generate the pdf file in jsp  Hi Friend, Try the following code: Thanks
Horizontal Bar Chart Example using JFreeChart
Horizontal Bar Chart Example using JFreeChart... a Horizontal bar chart using JFreeChart. This example showing you match.... createBarChart():  This method is used to create bar chart for given values
how to fetch data from mysql database table and draw a bar chart on that data using in jsp
how to fetch data from mysql database table and draw a bar chart on that data using in jsp  how to create bar chart fetch data from mysql database using in jsp.please give me a right code. yhanks in advance
Create a Pie Chart in jsp Page using JFree Chart
Create a Pie Chart in jsp Page using JFree Chart  Hello Sir I followed ur tutorial on "CREATE A PIE CHART IN JSP PAGE USING JFREE CHART... the pie chart report and after that save it to the desired location.Kindly help me
how to generate captcha in jsp page ? - JSP-Servlet
how to generate captcha in jsp page ?  hi friends, i would like to implement Captcha in login screen. i'm unsing struts. could you please give some sample codes to implement this. Thank you Ganesh  Hi, This link
how to connect the database using hibernet through servlet/jsp through form
how to connect the database using hibernet through servlet/jsp through form  plz give me the reply   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 http://www.roseindia.net/jsf/myfacesspring
How to display Jfreechart from servlet in jsp web page at specified location
How to display Jfreechart from servlet in jsp web page at specified... to display the chart in web page. I generated the chart using Jfreechart in Servlet which is in image format.plz sir give me the code to display this chart
display combination of a stacked area chart and line chart in one iframe using jfree - JSP-Servlet
. i m using struts1.1 servlet, jsp. please provide me the help or path...display combination of a stacked area chart and line chart in one iframe using jfree  hello i have a problem related to jfree chart, i want
generate pdf using jsp
generate pdf using jsp  how do i generate a pdf using jsp that should query the data from the database and write it into a pdf and download the same
how to create a bar chart in jsp by fetching value from oracle databse?
how to create a bar chart in jsp by fetching value from oracle databse?  i want to show the population of various states in a bar chart in my jsp page by fetching the data from my oracle table. i am using my eclipse as my IDE
jsp page authentication panel using jsp/servlet?
jsp page authentication panel using jsp/servlet?  I have 10 jsp jsp forms and 7 users and i want to grant variour permission like edit,delete and save for users dynamically on forms.So please refer me code
Page object - JSP-Servlet
Page object  Hello friends, How can we make use of PAGE object of implicit JSP object. If this is possible explain me about it's methods. I did not find any methods or explanation of this object. Pls help me
JFreechart Stacked Bar Chart
JFreechart Stacked Bar Chart JFreechart provides a way to create various charts by just using the methods of different classes. You are well aware of bar... Bar Chart. This chart actually displays the result of multiple queries stacks
Bar Chart Example using JFreeChart
Bar Chart Example using JFreeChart       This Example shows you how to create a bar chart using JFreeChart. Code given below creates a bar chart of scores of two teams
how to generate automatic bill based on selected values using jsp/javascript?
how to generate automatic bill based on selected values using jsp/javascript?  how to generate automatic bill based on selected values using jsp/javascript
Create a polar chart using JFreeChart
Create a polar chart using JFreeChart  ... a polar chart using JFreeChart. Code given below creates a simple polar chart.... createPolarChart(): This method is used to create bar chart for given values. It takes
how to add Arraylist filter for a jsp page showing results from a servlet
how to add Arraylist filter for a jsp page showing results from a servlet  hello sir/mam, in my project i have an arraylist showing results in a jsp..._TO_REPLACE_1 Please visit the following link: http://roseindia.net/jsp/servlet-jsp-data
How to upload files to server using JSP/Servlet?
How to upload files to server using JSP/Servlet?  How to upload files to server using JSP/Servlet
how to generate reports from oracle database using jsp and ajax code
how to generate reports from oracle database using jsp and ajax code  Hai masters i am new to this Java world. my team leader ask me to generate sales report data from oracle database to jsp page please any one know how to do
Doubt in using combination of JSP page and Java class. - JSP-Servlet
be disabled from clicking. How to go about doing this in a "JSP Page using...Doubt in using combination of JSP page and Java class.   I've got... the data in form bean and used in jsp file.  Well first of all thank
Draw Statistical chart in jsp
chart in jsp by getting values from database.. To draw a bar chart, we have used  JFreeChart Library. JFreeChart is a chart library used to generate different.../jsp/bar.jsp to the address bar and hit enter. The image of chart is displayed
How to generate pdf file on click of the links using jsp..
How to generate pdf file on click of the links using jsp..  How to generate the pdf file using jsp file. Generate table in pdf by using jsp.   Here is an example that will generate a pdf file into c drive.The pdf file
how to write a jsp form using html
how to write a jsp form using html  hi, i have written the code as below... but it is showing error. please help me how to resolve it. .html file...; <body> <form method="POST" action="Form1.jsp"> EmployeeNo: <
Box And Whisker Chart Example using JFreeChart
Box And Whisker Chart Example using JFreeChart       This Example shows you how to create a box and whisker chart using JFreeChart. Code of the chart given below
how to generate timetable - JSP-Servlet
how to generate timetable  can i have a jsp/servlet code for generating timetable for examinations for university like courses btech,cse ece etc... By giving starting date and ending date it will automatically generate
how to generate PDF file using JSP with net beans
how to generate PDF file using JSP with net beans  I am trying to generate PDF file using JSP. I even added itext5.0.6 jar file in library. It shows...\apache\jsp\hh_jsp.java:8: package com.lowagie.text does not exist import
How to pass an arraylist from servlet to jsp?
How to pass an arraylist from servlet to jsp?  Hello, Can anyone please tell me how to pass an arraylist from servlet to jsp? I have two arraylist... servlet to jsp? Thanks in advance
Category Step Chart Example using JFreeChart
Category Step Chart Example using JFreeChart... a category step chart using JFreeChart. Code of the chart shows you run rate.... JFreeChart: JFreeChart class object is used to create new chart according
Create multiple pie chart in single frame using JFreeChart
you how to create a multiple pie charts in a single frame in jsp page using... Create multiple pie chart in single frame using JFreeChart.... createMultiplePieChart(): This method is used to create bar chart
how to load values of html form into an excel table using java servlet?
how to load values of html form into an excel table using java servlet?   i have written a java servlet program, which has a html form to be filled. after filling the form the servlet generates a receipt and the values should
How to download files from server to local disk using ZIP format in JSP page - JSP-Servlet
How to download files from server to local disk using ZIP format in JSP... disk creting ZIP format for all files .how can create ZIp for all files pls help me as did like this but when i click on file it shows some depricted form and also
Candle Stick Chart Example using JFreeChart
Candle Stick Chart Example using JFreeChart       This Example shows you how to create a candle stick chart using JFreeChart. Code of the chart given below shows
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp?  I am using a single jsp form.. i did not get from another form.. i do not use 2 jsp form.. all.... Note: I am using only this jsp form.. i do not use
ArrayList from JSP to Servlet - JSP-Servlet
ArrayList from JSP to Servlet  Hi, I have an arraylist declared in a scriplet in a jsp page. how can i access the arraylist in a servlet which...)); %> How can I access this arraylist in a servlet. How
Bar charts and jsp
Bar charts and jsp  Hi, How to generate Dynamic Bar Chart Images using jsp with placing any image location in weebroots? Thanks in advance

Ads