Hello

Im trying to generate a image from a servlet and display it with browser.

Lets say I want to do something like this:

protected void doPost(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, java.io.IOException {  
                  BufferedImage bufferedImage = new BufferedImage(620, 420, BufferedImage.TYPE_INT_RGB);
		Graphics2D g2d = bufferedImage.createGraphics();
		g2d.setColor(Color.black);
		g2d.fillRect(0, 0, 620,420);  
		g2d.setColor(Color.yellow);
		bufferedImage.getGraphics();
}

This simply generates a box with a box rect. Ignore the yellow.....

Now obviously I have to get the response as I call the servlet again and display the image (as it physically isnt stored anywhere)

How can I do this? Or somewhere I can start at least.....

Thanks.

Recommended Answers

All 3 Replies

Hello

Im trying to generate a image from a servlet and display it with browser.

Lets say I want to do something like this:

protected void doPost(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, java.io.IOException {  
                  BufferedImage bufferedImage = new BufferedImage(620, 420, BufferedImage.TYPE_INT_RGB);
		Graphics2D g2d = bufferedImage.createGraphics();
		g2d.setColor(Color.black);
		g2d.fillRect(0, 0, 620,420);  
		g2d.setColor(Color.yellow);
		bufferedImage.getGraphics();
}

This simply generates a box with a box rect. Ignore the yellow.....

Now obviously I have to get the response as I call the servlet again and display the image (as it physically isnt stored anywhere)

How can I do this? Or somewhere I can start at least.....

Thanks.

check here maybe:http://www.exampledepot.com/egs/javax.servlet/GetImage.html

check here maybe:http://www.exampledepot.com/egs/java.../GetImage.html

Wouldnt I have to check for something like a postback? This way when the servlet is loaded, I can load the image (which doesnt exist as it is generated by the servlet) and display it.

Although I would like to save the image on the current directory and load it from there.

I dont think this is too difficult as Ive done it in courses Ive done and it took tops a hour. I right now dont remember how to do it so if someone could help out....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.