parameters

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Leonard

parameters

Post by Leonard » Mon Jul 01, 2002 7:52 am

I want to pass the parameter from the HTML page to change the width and the height of the servlet, but the value is still remaining the same as the initialize value! PLZ HELP ME!

below are the code that had created:

import com.jrefinery.data.PieDataset;
import com.jrefinery.data.DefaultPieDataset;
import com.jrefinery.chart.ChartFactory;
import com.jrefinery.chart.JFreeChart;
import com.jrefinery.chart.ChartFrame;
import com.jrefinery.chart.ChartUtilities;

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

import javax.swing.*;

import com.jrefinery.chart.*;
import com.jrefinery.chart.data.*;
import com.jrefinery.chart.ui.*;
import com.jrefinery.data.*;


public class pie_servlet extends HttpServlet{

ServletContext context=null;

Connection con = null;

public void init(ServletConfig config) throws ServletException{
super.init(config);
context=config.getServletContext();

try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(
"jdbc:oracle:thin:@solaris8dev.mecomb.po.my:1521:MEC_CRM",
"lim", "lim123");
}

catch (ClassNotFoundException e)
{
throw new UnavailableException(this, "Couldn't load the database driver");
}

catch (SQLException e)
{
throw new UnavailableException(this, "Couldn't get db connection");
}
}




public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

OutputStream out = response.getOutputStream();
int Background=0;
int Width=400;
int Height=400;

try {
Background = Integer.parseInt(request.getParameter("backgroundcolor"));
} catch (Exception e) {
}

try {
Width = Integer.parseInt(request.getParameter("width"));
} catch (Exception e) {
e.printStackTrace();
System.err.println("error" + Width);
// out.println();
}

try {
Height = Integer.parseInt(request.getParameter("height"));
} catch (Exception e) {
}
System.out.println(Background + " " + Height + " " + Width);
try
{
String req=request.getParameter("req");
Statement stmt=con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM com");

response.setContentType("IMAGE/GIF");

rs.next();

Double[] results=new Double[3];

results[0]= new Double(rs.getDouble("TELECOM"));
results[1]= new Double(rs.getDouble("SIME"));
results[2]= new Double(rs.getDouble("IBM"));

DefaultPieDataset dataset = new DefaultPieDataset(results);

JFreeChart chart = ChartFactory.createPieChart("Sample Pie Chart",dataset, true);

ChartUtilities.writeChartAsJPEG(out, chart, Width, Height);

out.close();

}

catch(SQLException e)
{
}

}
}

Bryan

Re: parameters

Post by Bryan » Mon Jul 01, 2002 9:02 am

Leonard

Three things to check
a. On the requesting page form can you check height and width are all lower case?
b. As you are using doGet you should be able to see in the requested URL.
c. The requesting page form should be a GET not POST.

Bryan


NB I use a method :

protected Dimension getImageSize(HttpServletRequest request) {
Dimension d = new Dimension(800, 600);
try {
d.width = Integer.parseInt(request.getParameter("width"));
} catch (Exception e) {
}

try {
d.height = Integer.parseInt(request.getParameter("height"));
} catch (Exception e) {
}

/// Some simple sizing checks
if (d.width > 2000) { d.width = 2000; }
if (d.width < 10) { d.width = 10; }
if (d.height > 1000) { d.height = 1000; }
if (d.height < 10) { d.height = 10; }

return d ;
}

Locked