• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Applet is not getting loaded in client machine

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am using an applet to display the reports in chart format.
I have deployed the web application in a tomcat server.
This is the code which generates an applet

ChartFrame frame = new ChartFrame("",chart);
frame.pack();
frame.setVisible(true);

When i run the application in my system, i could see the chart generated using applet. But when i accessed my application in another system using the required URL(replaced localhost with my system's ip),i couldn't see the chart. Rather it got generated in my machine.
Do i need to include any applet specific class?
Please help!!!

Thanks
Preetha
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds as if the code you posted is running on the server (which is your local machine, and not on the client). Is this really an applet? In other words, do you have a proper applet tag on an HTML/JSP page, or how is this code triggered to run?
 
preetha gayathri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No..... I haven't inserted any applet specific tag in my jsp.
I have just imported the awt package and using the function.
I have an index.jsp which is calling a servlet from where it is getting triggered.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlets and JSPs runs on the server; applets run on the client (in the web browser). You can't mix the two. The only way to run Java applets is by properly referencing them with applet tags in HTML/JSP pages.
 
preetha gayathri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

I created a separate jsp file which has the applet tag and is referencing the class file where the business logic reside.
But still i am facing the same problem
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you remove the chart code from the JSP page?
 
preetha gayathri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually i have an index.jsp from where an user selects for a particular chart type. From there, it calls a servlet called "Report.java" and initially my chart code was here. To tune it, i created a new jsp page called "chart.jsp" where i have put my chart code and removed it from my servlet.Whenever my servlet is called for a specific chart, the request gets redirected to chart.jsp using RequestDispatcher.
I am using applet tags inside chart.jsp. Is this the correcting way of referencing an applet from a class.

Thanks
Preetha
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't "reference an applet from a class" - if you have the applet tag in the JSP page, then the applet should be displayed correctly in the web browser - is that the case?

A JSP page or servlet can't contain anything that creates a GUI (like a Frame) - that would be displayed on the server, and not on the client, as you have found out.
 
preetha gayathri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my question is like, i have put that chart code(includes frame) in a jsp and my servlet calls this jsp whenevr it gets triggered.
But i didn't specify any applet tag like <applet/> anywhere in the jsp.
Because,I have put this jsp file in Webapp directory of Tomcat Server.
will this work?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i have put that chart code(includes frame) in a jsp and my servlet calls this jsp whenevr it gets triggered.


That's why you got the GUI to pop up on the server (your machine) when someone else accessed the JSP page.

But i didn't specify any applet tag like <applet/> anywhere in the jsp.


That's precisely the problem. A GUI that you want to show in the web browser needs to be an applet, not part of the JSP page.

Because,I have put this jsp file in Webapp directory of Tomcat Server.


I don't understand what this has to do with applets vs. JSPs. Anything you put directly into the webapps folder won't be accessible; it needs to be in one of its subdirectories (in other words, at the top level of the individual web apps).

If you tell us what you're really trying to do, we may be able to suggest ways to accomplish it. Are you creating chart images on the server? Do you want to show the images to the client, or does it need to be a full GUI?
[ March 26, 2008: Message edited by: Ulf Dittmer ]
 
preetha gayathri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just want to show the chart image to the client whenever he requests for a specific kind of chart from an user interface(have diff charts types internal to the application). This is my requirement now. I dont want to get generated in the server
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have two options of generating and showing a chart image.

First, include an applet in the JSP page that generates the chart on the client, and shows it in a GUI.

Second, create the chart on the server (you don't need a GUI for that), save the chart as an image on the server, and then display the image in the HTML/JSP page using an <img src="..."> tag.

I don't know what chart library you're using (or what other requirements you have), so I can't advise which of methods might be better suited. Generally, if there is no interactivity required -just a display of a particular chart- I'd say the second method is better, but it really depends on your circumstances.
 
preetha gayathri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As per your second option, for a single image to be stored in server and print it using HTML/JSP, it seems to be fine. But i am getting the data dynamically to generate the charts. And i have 21 options to select a chart and even if i save it as file in server, how do i get the image value in a HTML or a JSP?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

And i have 21 options to select a chart


I don't see how the number of options makes a difference as to how the chart might be generated. Can you elaborate?

if i save it as file in server, how do i get the image value in a HTML or a JSP?


You need to save it in the public web hierarchy, so that you can reference it from an HTML page via an IMG tag. Are you familiar with IMG tags?
 
preetha gayathri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not much familiar....

As you suggested, i am storing the chart as an image in local disk.
Then i retrieve the image file using the following piece of code in a jsp.
<%
String report = (String)request.getAttribute("report");
File f = new File("C://tomcat/webapps/Datagate/"+report+".png");
image=ImageIO.read(f);
%>
But when i try to show this image using <img> tag, nothing is getting displayed.
Correct me if this is wrong way of doing!!!
Are there any other ways to do this?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does your IMG tag look like? Something like the following should work:


The Java code you posted is not necessary. It doesn't help to read the image in the JSP page.
 
preetha gayathri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On the other way around , i tried something like writing the chart image to the output stream using the method "writeChartAsPNG" provided by JFreeChart.
It works fine
Thanks for your support!!!

- Preetha
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Preetha,
i have seen the conversation regarding the problem of displaying the image in the client browser and i also have the same problem .I am using jfreechart to create the chart and chartFrame to display the chart .
And you have given two options
1 . to use applet tag in the jsp
2. to display the image using the <img > tag
but i need to display the image in the GUI format for the user in the browser. I have seen the output image shown in the chart frame . and i need the same output to be displayed for my clients

Thanks And Regards
Suresh
 
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic