Vineet,
You can write a generic function to generate shapes based on user's input. For example if you have to draw a rectangle, you can take the width and height as the argument of the function and you can generate the shape. Some of the APIs you can use to generate shapes are:
java.awt.Color, java.awt.Font, java.awt.FontMetrics, java.awt.Graphics2D etc.
You can call this function in the service method of your servlet to generate the image passing the required inputs for image generation. For writing the image on the server you need to do following things:
1. Set the content type to image/jpg. [This is must]
2. Use ImageIO to write the image to servlet.
3. Write a HTML image tag in your jsp which simply points to your servlet. (Also pass the required inputs, you may use query string)
Code snippet for Step 1 & 2:
Hope this helps.
- Kamlesh