Solved

JCharts Problem Outputting mixed HTML / Chart page

Posted on 2003-10-31
6
294 Views
Last Modified: 2010-08-05
Im using SourceForge's JChart and im trying to output a HTML with a chart integrated. I can output the chart on its own but if i add any html to the servlet (its all working via a servlet NO jsp) I get the image in text for ie random rubbish

ie

<HTML>
<TITLE>
</TITLE>
<BODY>
***runs the chart code here
</BODY>
</HTML>

What am i doing wrong? the Jcharts apparantly does the changin of the responce type itself

How do i integrate them?

0
Comment
Question by:ashtowers
  • 2
  • 2
6 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 40 total points
ID: 9658128
errrr....

so you are trying to send back HTML and a jpg/gif in the same response stream?

That won't work...the response is either text/html OR image/gif ... not both in the same response...

You need to output some HTML like:

<HTML>
<TITLE>
</TITLE>
<BODY>
<IMG SRC="imageServlet?param1=a&param2=b&param3=c">
</BODY>
</HTML>

then have another servlet (imageServlet in this example) which does the image...
0
 

Expert Comment

by:ashcarrot
ID: 9658210
How would you deal with multiple items to chart (ie APPLE 2, BANANA 3, PINEAPPLE 3) ie you dont know how many lines to draw in your bar chart

is IMG resticted to 255(or something like that) characters after the URL like the GET method?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9658222
I'm confused...

Who's asking this question?
0
 
LVL 1

Expert Comment

by:avatar21
ID: 13617966
Yup, I agree with the question ... (is IMG resticted to 255(or something like that) characters after the URL like the GET method?)
Cause I'm having the same question in mind. But I don't think IMG had as little limit size as 255, even there is there will be more than enough ... and instead GET have a limit lenght of 255.

Regarding the suggestion of:
<HTML>
<TITLE>
</TITLE>
<BODY>
<IMG SRC="imageServlet?param1=a&param2=b&param3=c">
</BODY>
</HTML>

Actually I'm looking for the same thing, any example provided(the java src perhaps)? Then there is an additional issue worries me:"what types of image client updated to the server(jpeg,gif,png...) will be another circumstanses we need to handle in our servlet codes, right? Or it's just transparent to us(auto handle tru html's <input> tag)?"

Ya forgot to tell you all my objective, I'm doing something like capturing and storing images from client into mysql database's Blob type. Then retrieving it and displaying it back to a dynamic page(a jsp most likely)!
0
 
LVL 1

Expert Comment

by:avatar21
ID: 13643667
ashcarrot , few days b4 I had te excactly  same quetion like u ask ... 255 limit size of GET method. But I've figured it out, it wasn't.

I do not know how your code of getting the Blob type(image) from your db, as I crawl over the web ... there's plenty of solutions. PS: but none is good/ effective/ performance wise!

I use a OutputStream type to make a response to my client in a "ShowBlobImage.class", what it basically do is retrieving blob from db using byte[] and response the object. It can be query by ".../ShowBlobImage?obj_id=?"!

I strongly agree with TimYates's comment, about text/html and stream(image/*) cant be together as a response. So dun do your query in something like:

 <IMG SRC="imageServlet?param1=a&param2=b&param3=c">

, instead make it saperate like:
<IMG SRC="imageServlet?param1">
<IMG SRC="imageServlet?param2=b">
<IMG SRC="imageServlet?param3=c">

In advance you can consider using Object to encapsulate all field's value in a data object(including size, type, and filename). By doing so, is easier for a Bean construction.

Last but  not least, don't forget to set your data size and type by calling:
response.setContentType(myObj.getType());
response.setLength((int)myObj.getSize()); // since getSize() return a Long type

Regards,
Avatar Ng
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now