Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet how to generate a bar chart on a JSP PAGE using the arraylist object passed form the servlet.(using jfreechart)
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Aarushi Agarwal
how to generate a bar chart on a JSP PAGE using the arraylist object passed form the servlet.(using jfreechart)
2 Answer(s)      3 years and 2 months ago
Posted in : JSP-Servlet


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.


Advertisement
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
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
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
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 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
how to create bar chart in jsp using msaccess database
how to create bar chart in jsp using msaccess database  type... in the jsp file: /bar.jsp Generated servlet error: C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\chetana\org\apache\jsp\bar_jsp.java
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
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 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... is used to create stacked bar chart for given values. It takes title, domain
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...); JFreeChart chart = ChartFactory .createBarChart3D( "Test", "Id", "Score
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
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
create bar chart in jsp using msaccess database
create bar chart in jsp using msaccess database  type Exception... Foundation\Tomcat 5.0\work\Catalina\localhost\chetana\org\apache\jsp\bar_jsp.java:57... occurred at line: 8 in the jsp file: /bar.jsp Generated servlet error
generate charts using JSP
generate charts using JSP  any one know coding for generate bar chart or pie chart using JSP
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
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
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 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
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
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
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
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
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...(): This method is used to create bar chart for given values. It takes title, dataset
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... Draw Statistical chart in jsp   
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
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 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: http://www.roseindia.net/jsf/myfacesspring/loginRegistration.shtml Hope
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
 

 

 

DMCA.com