Home Struts Struts1 Img Tag:
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Img Tag:

Advertisement
html:img Tag : Renders an HTML element with the image at the specified URL. This tag allows dynamic generation of an image as specified attributes of this tag.

Img Tag<html:img>:

     

html:img Tag : Renders an HTML <img> element with the image at the specified URL. This tag allows dynamic generation of an image as  specified attributes of this tag.

Note: The base URL for this image is calculated directly based on the value specified in src, page, or action or page, or indirectly by looking up a message resource string based on the srcKey or pageKey attributes.
* There must be specified exactly one of these attributes.
 

Name Description
border

This attribute specifies the width of the border surrounding the image.

name

The name  attribute specifies The  JSP bean that contains a Map representing the query parameters (if property is not specified), or a JSP bean whose property getter is called to return a Map (if property is specified).

page

The module-relative path, starting with a slash, of the image to be displayed by this tag. The rendered URL for this image will automatically prepend the context path of this web application (in the same manner as the page attribute on the link tag works), in addition to any necessary URL rewriting. You must specify either the page attribute or the src attribute.

action

The action, starting with a slash, that will render the image to be displayed by this tag. The rendered URL for this image will automatically prepend the context path of this web application (in the same manner as the action attribute on the link tag works), in addition to any necessary URL rewriting. You must specify the action, page attribute or the src attribute.
Additionally, you can specify a module prefix for linking to other modules.

property

The name of a property of the bean specified by the name attribute, whose return value must be a java.util.Map containing the query parameters to be added to the src URL. You must specify the name attribute if you specify this attribute.

scope

Specified the scope within which to search for the bean specified by the name attribute. If not specified, all scopes are searched.

width

This attribute provides the width of the image being displayed. This parameter is very nice to specify (along with height) to help the browser render the page faster.

Example Illustrating the use of the Rewrite<html:img> tag :
Here you will learn to use the Struts Html  <html:img>tags. 
We will cover an example that will show a working of<html:img>tags

Example code :
Creating an Action Class      : Not Required here.
Creating Form Bean     : Not Required here.
Defining the global-forwards     : Not Required here.
Developing the Action Mapping in the struts-config.xml   : Not Required here.


Developing the HtmlImageTag.jsp page :

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
 <body bgcolor="#999933"
  <h3><font color="#FFFF33">HTML IMAGE TAG DEMO</font></h3>
  <html:img page="/images/servicesbanner.gif" width="20%" border="2"/>
  </body>
</html>

Add the following line in the index.jsp to call the form.
<a href=" HtmlImageTag.jsp"> HtmlImageTagDemo</a><br/> 

Building and Testing the Example  :
Build , deploy and Test  the application . 
Open the browser and navigate to the HtmlImageTag.jsp page. 
Your browser displays the following page HtmlImageTag.jsp and see the output .

 


Above Demo  displays the working of  <html:img>tag.

     
Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 10, 2008

Ask Questions?    Discuss: Img Tag:  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com