< html:image /> html tag

< html:image /> html tag

Previous Home Next

 

The struts image Tag is used to render of html <input> element of type image.The image URL for generated is calculated directly the value identified in the src or page attributes.

 
You must specify one of the scr and page attributes or you can indirectly by looking up a message resource string based on the srcKey or pageKey attributes.when We submitted this request, see the information below on the property attribute. The <html:image> tag must be nested inside the body of an <html;form> tag.

The struts image tag have following attributes:- 

  • styleId :- This is Identifier to be assigned to this HTML element and renders an 'id' attribute.
  • tabindex :- This is tab ascending positive integers order for this element.
  • title :- This attributes is  the advisory title for this element.
  • titleKey :-This attributes is  the advisory title for this element basically this is message resources key.
  • value :-This is used when value  transmitted if image button is checked.
  • style :- In this element you can applied CSS style.
  • styleClass :- In this element you can applied CSS stylesheet class.
  • align :- this is alignment option.

The Following are many other attributes which we can use :

  • accesskey 
  • alt
  • altKey
  • border
  • bundle
  • dir
  • disabled
  • indexed
  • lang
  • locale
  • module
  • onblur
  • onchange
  • onclick
  • ondblclick
  • onfocus
  • onkeydown
  • onkeypress
  • onkeyup
  • onmousedown
  • onmousemove
  • onmouseout
  • onmouseover
  • onmouseup
  • page
  • pagekey
  • property 


Directory Structure of ImageTagExample in Struts 1.3 Using MyEclipse IDE




index.jsp

<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<html:html>
<head>
<title><bean:message key="label.title"/></title>
</head>
<body>
<h3><bean:message key="label.header"/></h3>
<html:link action="/imageAction">Image Tag Example Link</html:link>
</body>
</html:html>

web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
 
<web-app>
  <display-name>Maven Struts Examples</display-name> 
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>
        org.apache.struts.action.ActionServlet
    </servlet-class>
    <init-param>
        <param-name>config</param-name>
        <param-value>
         /WEB-INF/struts-config.xml
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet> 
  <servlet-mapping>
       <servlet-name>action</servlet-name>
       <url-pattern>*.do</url-pattern>
  </servlet-mapping> 
</web-app>

struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" 
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
  <form-beans/>
  <global-exceptions />
  <global-forwards />
  <action-mappings >
    <action path="/imageAction" type="org.r4r.struts.ImageAction">
         <forward name="success" path="/success.jsp"/>
		</action>
  </action-mappings>
  <message-resources parameter="org.r4r.struts.ApplicationResources" />
</struts-config>

ImageAction.java

package org.r4r.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class ImageAction extends Action {
	public ActionForward execute(ActionMapping mapping,ActionForm form,
		HttpServletRequest request,HttpServletResponse response) throws Exception{
		return mapping.findForward("success");
	}
}

ApplicationResources.properties

# Resources for parameter 'org.r4r.struts.ApplicationResources'
# Project Struts1.3_ImageTagExample
label.title= Struts html:image tag Example
label.header= Struts html:image tag Example

success.jsp

<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html>
<head>
<title><bean:message key="label.title"/></title>
</head>
<body>
<h3><bean:message key="label.header"/></h3>
<html:image page="/mukund.gif" property=""></html:image>
</body>
</html>

Output




Previous Home Next