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:
Advertisements
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 implementedBar 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 databasehow 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
Bar Chart in JSP - JSP-ServletBar 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 databasecreate
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 databasecreate
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 valuesHow 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
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 a Pie Chart in jsp Page using JFree ChartCreate 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-Servlethow 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
generate pdf using jspgenerate 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
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-ServletPage 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 ChartJFreechart 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
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
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 write a jsp form using htmlhow 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:
<
how to generate timetable - JSP-Servlethow 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 beanshow 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
ArrayList from JSP to Servlet - JSP-ServletArrayList 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 jspBar charts and jsp Hi,
How to
generate Dynamic
Bar Chart Images
using jsp with placing any image location in weebroots?
Thanks in advance