sanjay2006
03-15-2006, 04:02 AM
Hello friends,
I am very new in Java (servlets). I am trying to display (created) image depends on the input parameters. example: i might send parameter as square/circle/poly/rectangle etc to the servlet. Servlet will open my image from disk and draw picture of the parameter sent.
e.g. if i sent a "rectangle" as as a parameter value, servlet will draw a rectangle on a loaded image (which can be just blank image). BUT till here it is okay, my question comes here:
We can't use response.setContentType("image/gif"); and response.setContentType("text/html"); together... I want to display some text which depends on the parameter and text is calculated by the same servlet which is drawing image. I do not want to draw a text on image, want to print it separately on a html page bellow the image.
sample program: (bellow program need to edit to make runnable)
import Acme.JPM.Encoders.GifEncoder;
public class SampleServlet extends HttpServlet {
public void doGet or doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
out = res.getOutputStream();
res.setContentType("image/gif");
shape = req.getParameter("shape");
URL url = null;
Image image;
url = new URL ("http://hostname/examples/example.gif");
mt = new MediaTracker(frame);
image = Toolkit.getDefaultToolkit().getImage(url);
mt.addImage(image, 0);
w = image.getWidth(frame);
h = image.getHeight(frame);
Image offscreen = frame.createImage(w, h+200);
g = offscreen.getGraphics();
g.drawImage(image,2,2,frame);
g.drawShape .... dummy statement, this will draw shape
// do some manipulation...
// here I am expecting bunch of "xyz" text lines from above manipulation.
GifEncoder encoder = new GifEncoder(offscreen, out);
encoder.encode();
}
This servlet executes nicely but displays only sample image in the html frame; can someone tell me how can i display the "xyz" text lines generated by same servlet in a seperate table, just bellow the image???
Thanks in advance.
Sanjay
I am very new in Java (servlets). I am trying to display (created) image depends on the input parameters. example: i might send parameter as square/circle/poly/rectangle etc to the servlet. Servlet will open my image from disk and draw picture of the parameter sent.
e.g. if i sent a "rectangle" as as a parameter value, servlet will draw a rectangle on a loaded image (which can be just blank image). BUT till here it is okay, my question comes here:
We can't use response.setContentType("image/gif"); and response.setContentType("text/html"); together... I want to display some text which depends on the parameter and text is calculated by the same servlet which is drawing image. I do not want to draw a text on image, want to print it separately on a html page bellow the image.
sample program: (bellow program need to edit to make runnable)
import Acme.JPM.Encoders.GifEncoder;
public class SampleServlet extends HttpServlet {
public void doGet or doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
out = res.getOutputStream();
res.setContentType("image/gif");
shape = req.getParameter("shape");
URL url = null;
Image image;
url = new URL ("http://hostname/examples/example.gif");
mt = new MediaTracker(frame);
image = Toolkit.getDefaultToolkit().getImage(url);
mt.addImage(image, 0);
w = image.getWidth(frame);
h = image.getHeight(frame);
Image offscreen = frame.createImage(w, h+200);
g = offscreen.getGraphics();
g.drawImage(image,2,2,frame);
g.drawShape .... dummy statement, this will draw shape
// do some manipulation...
// here I am expecting bunch of "xyz" text lines from above manipulation.
GifEncoder encoder = new GifEncoder(offscreen, out);
encoder.encode();
}
This servlet executes nicely but displays only sample image in the html frame; can someone tell me how can i display the "xyz" text lines generated by same servlet in a seperate table, just bellow the image???
Thanks in advance.
Sanjay