How to generate dynamic images(specifically charts) in servlets and send it to an applet.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   vadiraj_deshpande
Posted On:   Wednesday, April 4, 2001 08:17 AM

I'm working on a website project. In that I have to evaluate the answers sent by the client and send the result in the form of a chart back to client. I'm using an applet to present questions and the applet is sending the answers correctly to server. Now I have the answers and stratergy to evaluate the answers but I dont know how to generate dynamic images and send back to same client applet or some other applet. I read from Java servlets(O'reilly) that JDK1.2 has some jpg encoder classes. So if I have the encoder which will encode an image to gif or jpg i can send it to client through res.getOutputStream() I also heard that some encoders are available free on net but i can't afford to those. I have jdk1.2 and I want to use th   More>>

I'm working on a website project. In that I have to evaluate the answers sent by the client and send the result in the form of a chart back to client. I'm using an applet to present questions and the applet is sending the answers correctly to server.
Now I have the answers and stratergy to evaluate the answers but I dont know how to generate dynamic images and send back to same client applet or some other applet.
I read from Java servlets(O'reilly) that JDK1.2 has some jpg encoder classes. So if I have the encoder which will encode an image to gif or jpg i can send it to client through
res.getOutputStream()

I also heard that some encoders are available free on net but i can't afford to those. I have jdk1.2 and I want to use the jpg encoders built in jdk.
Will you help me in this?

   <<Less

Re: How to generate dynamic images(specifically charts) in servlets and send it to an applet.

Posted By:   faisal_parwani  
Posted On:   Friday, April 6, 2001 10:39 PM

first look at my code below

//see the code first

i am creating a BufferedImage object , geting a graphic device context 'g'
and using this 'g' i am drawing a circle , rectangle and etc.
response return type is image/jpeg and than using java JPEG encoder this
image is converted to jpeg , and returned to browser.

Charts:
this the area where you have to think about how to creat charts , size of
image , how to draw charts using company related information .
but i will not be a problem for you,
any way try your best and inform me if you have any problem

second now u have to see how to call this servlet via applet.


by
faisal parwani.

see the code below




import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.sun.image.codec.jpeg.*;
import java.awt.image.*;
import java.awt.*;


public class JPEGServlet extends HttpServlet
{
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException

{
response.setContentType("image/jpeg");
ServletOutputStream out =
response.getOutputStream();
BufferedImage image = new
BufferedImage(100,100, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(Color.green);
g.fillRect(0, 0, 100, 100);
g.setColor(Color.red);
g.drawOval(0, 0, 100,100);
JPEGImageEncoder encoder
=JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
}

}
About | Sitemap | Contact