To display data in a table and as an image try the following incomplete
code:
public class GraphikServlet extends HttpServlet {
public void doPost (HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
ServletOutputStream out = res.getOutputStream();
// ... get data from database
out.println("<TABLE BORDER>");
// ... print data in tabular form
out.println("</TABLE>");
// show data as an image by calling the doGet-method of GraphikServlet:
out.println("<IMG SRC=\"/servlet/GraphikServlet\">");
out.println("</BODY></HTML>");
out.close();
}
public void doGet (HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("image/jpeg");
res.setHeader("pragma", "no-cache");
res.setHeader("expires", "0");
ServletOutputStream out = res.getOutputStream();
// get the data and declare width and height of the image...
BufferedImage img = new
BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = img.createGraphics();
// create the image:
g2.clearRect(0,0,width,height);
g2.setColor(Color.black);
g2.drawRect(0,0,width-1,height-1);
// ...
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(img);
param.setQuality(1.0f,true);
encoder.encode(img,param);
out.close();
}
}
The servlet should be called first by the post-method. This method sends the
requested data back in tabular form and in addition an IMG-tag, which leads
to a further request to the same servlet, but now the get-method is
activated. So the user gets the requested data as a table and as an image on
his browser.
The servlet needs more code for keeping the data between both requests, for
example by a cookie.
The code should work with Java 2.
If you would like to create a GIF-file instead of JPEG's, you could use the
Acme.JPM.Encoders-package
(http://www.acme.com/java/software/Acme.JPM.Encoders.GifEncoder.html) and
replace the JPEG-related code above by:
GifEncoder encoder = new GifEncoder(img,out);
encoder.encode();
Instead of showing images as GIF or JPEG you could also use applets. After
creating the image here the user can still change some graphic-parameters
interactively. The IMG-tag should then be replaced by
<APPLET CODE="GraphikApplet.class" WIDTH="500" HEIGHT="300"
CODEBASE="..">
<PARAM NAME=werte
VALUE="-3.1416~0.0~-2.827~0.309~2.827~0.309~3.1416~0.0~">
</APPLET>
Here the data can be send immediately by a PARAM-tag, so no
HttpSession-Class or something similar is needed for keeping the data
between two requests. The CODEBASE-attribut is important, for that applet
can be found. The applet should not be put in the servlet-subdirectory
itself, because most servers accept there only servlets.
Good luck
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html