aspose file tools*
The moose likes Applets and the fly likes showing applet embedded  in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "showing applet embedded  in jsp" Watch "showing applet embedded  in jsp" New topic
Author

showing applet embedded in jsp

abhishek rawat
Greenhorn

Joined: Mar 25, 2011
Posts: 11

Hi,

I am creating pie chart using jfreechart , I am dynamicaly taking the values from DB and showing them in pie form. I have two java file one for database and other is for showing applet (applet class have main , which calls the DB class). All code properly works well in java. But I want these to be run through jsp. such that it get embedded in jsp. I am trying many ways but unable to do it . Could you please guide me how to move forward.

Thanks
Abhishek

Below is my applet .java file
-------------------------------------------------
package Pie_Chart;

import javax.swing.*;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RectangleEdge;
import org.jfree.ui.RefineryUtilities;

public class PieChart extends ApplicationFrame
{

private Object chart;


/**
* Creates a new demo instance.
*
* @param title the frame title.
*/
public PieChart(String title) {


super(title);

DB db = new DB();
db.dbConnect("jdbc:sqlserver://newinfomine:3468;instanceName=MSSQL2005", "eGActiveDB_762", "eGActiveDB_762" );
JPanel panel = new JPanel(new GridLayout(2, 2));
DefaultPieDataset dataset = new DefaultPieDataset();
DefaultPieDataset dataset1 = new DefaultPieDataset();
dataset.setValue("January "+DB.ravi_case, DB.ravi_case);
dataset.setValue("February "+DB.ravi_case_feb, DB.ravi_case_feb);
dataset.setValue("March "+DB.ravi_case_mar, DB.ravi_case_mar);

dataset1.setValue("January "+DB.pradeep_case, DB.pradeep_case);
dataset1.setValue("February "+DB.pradeep_case_feb, DB.pradeep_case_feb);
dataset1.setValue("March "+DB.pradeep_case_mar, DB.pradeep_case_mar);




JFreeChart chart1 = ChartFactory.createPieChart("Ravi Case", dataset, false, false, false);
JFreeChart chart2 = ChartFactory.createPieChart("Pradeep Case", dataset1, false, false, false);

panel.add(new ChartPanel(chart1));
panel.add(new ChartPanel(chart2));
panel.setPreferredSize(new Dimension(800, 600));
setContentPane(panel);



}

public static void main(String[] args)
{
PieChart demo = new PieChart("Pie Chart");
demo.setVisible(true);
}

}
Haina Minawa
Ranch Hand

Joined: Oct 13, 2011
Posts: 119
What have you been trying to do? What problem did you encounter?
Did you use <applet> tag to embed the applet into the JSP page?

abhishek rawat
Greenhorn

Joined: Mar 25, 2011
Posts: 11

I even tried the <applet> tag but it is not loading in the browser, I searched Internet and used all the way but no success. Could you please help me, if possible a sample JSP calling this applet will be much appreciated.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
What did you put in the applet tag? Were there any messages in the Java Console?

The code you posted is not an applet, so you would have had to rewrite it.
abhishek rawat
Greenhorn

Joined: Mar 25, 2011
Posts: 11

"The code you posted is not an applet, so you would have had to rewrite it."

Sorry but could you please explain me why this is not applet. I am using third party API(jfreechart) to show bar and pie in applet.

abhishek rawat
Greenhorn

Joined: Mar 25, 2011
Posts: 11

@ Tim... I got what you were trying to say .. it should extend Applet to be a applet.
abhishek rawat
Greenhorn

Joined: Mar 25, 2011
Posts: 11

But you guys have any idea ..How I will call the above file in jsp?
abhishek rawat
Greenhorn

Joined: Mar 25, 2011
Posts: 11

But you guys have any idea ..How I will call the above file in jsp?..which extends application frame...
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
How I will call the above file in jsp?

By using an applet tag, as has been suggested before. Start reading here: http://download.oracle.com/javase/tutorial/deployment/applet/index.html

How I will call the above file in jsp?..which extends application frame...

As I said, you need to rewrite your code so that it extends Applet or JApplet.
Andrew Thompson
Ranch Hand

Joined: Aug 05, 2010
Posts: 77
    
    5
There should be no (J)Applet (or (J)Frame) used here. Instead:
  • Have a servlet access the DB*, prepare the image, and serve it as image content.
  • Use JSP to access the servlet and display the image that it produces.

  • * If Java client side code can access the DB, so can hackers. That is a bad thing. Hide the DB behind some protective servlet.


    Andrew Thompson
    http://pscode.org/
    abhishek rawat
    Greenhorn

    Joined: Mar 25, 2011
    Posts: 11

    Hi All,

    I tried to save my applet on the server machine using robot method and it is working properly



    But the issue here is..it is capturing whole screen ..instead of just applet...Please let me know if there is another way of saving applet .
    Andrew Thompson
    Ranch Hand

    Joined: Aug 05, 2010
    Posts: 77
        
        5
    abhishek rawat wrote:..I tried to save my applet on the server machine using robot method and it is working properly ..
    But the issue here is..it is capturing whole screen


    What is the connection between showing a chart in a web page, and saving a screen-shot (of an applet or the screen) to the server?

    As to "it is working properly" - I bet you have not tried this yet in a situation where the server and client are 2 different machines. Would I win that bet? ;)
    Haina Minawa
    Ranch Hand

    Joined: Oct 13, 2011
    Posts: 119
    abhishek rawat wrote:But you guys have any idea ..How I will call the above file in jsp?..which extends application frame...


    As Andrew suggested before, you should consider the solution of generating an image version of the report in a Servlet, then push the image to client (via a call to the Servlet in your JSP page, maybe).
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: showing applet embedded in jsp