Tools and Technologies used in this article :

  1. JSP / Servlet

  2. Eclipse 3.7

  3. Tomcat


1. Create Dynamic Web Project

Select from the menu File --> New --> Dynamic Web Project (say 'ImageCreatorServlet').


2. Write a Java Servlet

Create a servlet class (say com.srccodes.examples.servlet.ImageCreator)
Modify the java class as per the following code.

File :


3. Add servlet mapping

Add servlet mapping for the servlet ImageCreator in web.xml.

File : web.xml


4. Create a Jsp page

Create a jsp page (say test.jsp) and add a <img> html tag to display the dynamically generated image.

File : test.jsp


5. Overall Project Structure

Overall Project Structure


6. Run Your Code

Right click on 'test.jsp' and select from context menu 'Run As' --> 'Run on Server'.


7. Browser Output

Eclipse will open a browser and an image of 'Hello World!' will be shown in the browser.

Hello World!


Download Source Code