Wednesday, January 8, 2014

To Insert an image using tag in JSP (in NetBeans IDE)

To insert an image in JSP using <img> tag you need to follow the given steps...

  • First put the "images folder" in  "Web Pages" Folder. Place your images in image Folder.
         Web pages folder stores all your web pages which you have created!
  • Now write the code given below...

String ima=rs.getString("CoverImage");        
     //getting the image name from MySql database.(eg hand.JPG)
String image=request.getContextPath()+"/images/"+ima+"";              
                              //ima is the String var 
<img alt="image" src="<%= image %>" height="100" width="100"/>
//place this anywhere you want to display the image

You can also mention the name of your image directly in place of "ima" object.
String image=request.getContextPath()+"/images/photo.JPG";   

No comments:

Post a Comment