< html:button /> html tag

< html:button /> html tag

Previous Home Next

 

Struts button tag is a render of  an HTML <input> element of input type button .This is populated from the specified value or the content of this tag body. The <html:button/> tag must be nested inside the body of an <html:form/> tag.


 
<html:form action="“login.do”"><html:button>This Tag have many attribute like value ,property ,onclick, onfocus ,onmousedown ,onmousemove etc. It has on mandatory attribute property.</html:button></html:form>
<html:form action="“login.do”"></html:form>
<html:form action="“login.do”">User Name:</html:form>
<html:form action="“login.do”">
<html:button property="“uesrname”">Password:<html:button property="“uesrname”"></html:button></html:button></html:form>

<html:form action="“login.do”"><html:button property="“uesrname”"><html:button property="“uesrname”"></html:button></html:button></html:form>

There are following attributes:-

1.accesskey :-This attributes is used to immediately move focus to this element.

2.alt :- This attributes is the alternate text for this element

3.onfocus :- This is used receives input focus after that event handler executed .

4.onmousedown :- This attributes is under the mouse pointer and a mouse button is depressed than event handler executed.

5.onmousemove :-This attributes is used under the mouse pointer when the pointer is moved than event handler executed.

The Following are many other attributes which we can use :

  • altKey 
  • bundle
  • dir 
  • disabled 
  • indexed
  • lang 
  • onblur
  • onchange
  • onclick
  • ondblclick
  • onkeydown
  • onkeypress
  • onkeyup
  • onmouseout
  • onmouseover
  • onmouseup
  • property
  • style
  • styleClassstyleId 
  • tabindex 
  • title
  • titleKey 
  • value


Directory Structure of ButtonTagExample 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>
<script language="JavaScript">
            function clickme()
            {
                confirm("You click the button.");
            }
</script>
</head>
<body>
<h3><bean:message key="label.header"/></h3>
<html:form action="/buttonAction">
<bean:message key="label.name"/>:
<html:text property="name" name="buttonForm"/><br/>
<bean:message key="label.technology"/>:
<html:text property="technology" name="buttonForm"/><br/>
<br/>
<html:button property="name" onclick="clickme()"><bean:message key="label.button"/></html:button>
</html:form>
</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>
    <form-bean name="buttonForm" type="org.r4r.struts.ButtonForm"/>
  </form-beans>
  <global-exceptions />
  <global-forwards />
  <action-mappings >
    <action path="/button" type="org.apache.struts.actions.ForwardAction" parameter="/index.jsp"/>
		<action path="/buttonAction" type="org.r4r.struts.ButtonAction" name="buttonForm" input="/index.jsp">	
         <forward name="success" path="/success.jsp"/>
		</action>
  </action-mappings>
  <message-resources parameter="org.r4r.struts.ApplicationResources" />
</struts-config>

ButtonForm.java

package org.r4r.struts;

import org.apache.struts.action.ActionForm;

@SuppressWarnings("serial")
public class ButtonForm extends ActionForm {
	private String name;
	private String technology;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getTechnology() {
		return technology;
	}
	public void setTechnology(String technology) {
		this.technology = technology;
	}
}

ButtonAction.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 ButtonAction extends Action {
	public ActionForward execute(ActionMapping mapping,ActionForm form,
		HttpServletRequest request,HttpServletResponse response) throws Exception{
		@SuppressWarnings("unused")
		ButtonForm passwordForm=(ButtonForm)form;
		return mapping.findForward("success");
	}
}

ApplicationResources.properties

#label message
label.title=Struts html:button tag example
label.header=Struts html:button tag example
label.name = User Name 
label.technology = Technology Name
label.button = Button

success.jsp

<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html:html xhtml="true">
<head>
<title><bean:message key="label.title"/></title>
<html:base/>
</head>
<body>
<h3><bean:message key="label.header"/></h3>
<h4><bean:message key="label.name"/>:-
<bean:write name="buttonForm" property="name" /></h4>
<h4><bean:message key="label.technology"/>:-
<bean:write name="buttonForm" property="technology" /></h4>
</body>
</html:html>

Output





Previous Home Next