From your query it seems that you want to show the gifs in the web page dynamically, depending on context .
Your problem can be solved in a number of ways...
If the number of Gifs is small, you can code it like this....
<img src="<% case(gifNo){
case 0:%>zero.gif<%;
break;
case 1: %>one.gif<%;
break;
default: %>default.gif<%;
} %>" >
For clarity I have coded the different cases in different lines.. You might have to code them on one single line..
If you have many images , to store the images in a data base will be a good idea.
Another approach will be to store the gif file names only on the database , and store the actual images in the image folder. Code a switch case as in the first example , and instead of the hard coded gif names , print the vartiable containing the gif name...
Hope this helps....
Shubhrajit
Hi srimathi,
Here I am giving you two ways to create dynamic GIFs.
Example:1
=========
Frame frame = null;
Graphics g = null;
FileOutputStream fileOut = null;
try
{
//create an unshown frame
frame = new Frame();
frame.addNotify();
//get a graphics region, using the frame
Image image = frame.createImage(WIDTH, HEIGHT);
g = image.getGraphics();
//manipulate the image
g.drawString("Hello world", 0, 0);
//get an ouputstream to a file
fileOut = new FileOutputStream("test.gif");
GifEncoder encoder = new GifEncoder(image, fileOut);
encoder.encode();
}
catch (Exception e)
{
;
}
finally
{
//clean up
if (g != null) g.dispose();
if (frame != null) frame.removeNotify();
if (fileOut != null) {
try { fileOut.close(); }
catch (IOException ioe) { ; }
}
}
Example 2:
=========
<jsp:useBean id="imageBean" class="package.ImageBean" scope="page" />
<%
String imageNo = request.getParameter("ImageNo");
byte[] jpegArray = imageBean.getJPEG(Integer.parseInt(imageNo));
response.setContentType("image/jpeg");
ServletOutputStream op = response.getOutputStream();
op.write(jpegArray, 0, jpegArray.length);
%>
I hope it will help you out.
Regards,
Tirumalarao
Developer TechnicalSupport,
Sun Microsystems,India.