< html:text /> html tag
Previous | Home | Next |
This tag is used to text input type element.Text is a human-readable sequence of character.This tag must be nested inside the dorm tag body.Example:-<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <html:form action="/Login"> User Name :<html:text name="LoginForm" property="username" /> Password :<html:password name="LoginForm" property="password" /> <html:submit value="login" /> </html:form>The struts text tag have following attributes:-
- property* :- This is identifies the name of the input field being processed and name of the bean property that maps to this input elements.This is required attributes.
- tabindex :- This is tab ascending positive integers order for this element.
- title :- This attributes is the consultant title for this element.
- titleKey :-This attributes is the consultant title for this element basically this is message resources key.
- value :-This is used when label should note that the body of the tag .This can also be used as button label
- style :- In this element you can applied CSS style.
- styleClass :- In this element you can applied CSS stylesheet class.
The Following are many other attributes which we can use :-
- accesskey
- alt
- altKey
- disabled
- onblur
- onchange
- onclick
- ondblclick
- onfocus
- onkeydown
- onkeypress
- onkeyup
- onmousedown
- onmousemove
- onmouseout
- onmouseover
- onmouseup
Directory Structure of TextTagExample in Struts 1.3 Using MyEclipse IDEindex.jsp<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> <html> <head> <title>Struts html:text tag example</title> </head> <body> <h3>Struts html:text tag example</h3> <html:form action="/textAction"> <bean:message key="label.name"/>: <html:text property="name" name="textForm"/><br/> <bean:message key="label.course"/>: <html:text property="course" name="textForm"/><br/> <bean:message key="label.college"/>: <html:text property="college" name="textForm"/><br/> <bean:message key="label.phone"/>: <html:text property="phone" name="textForm"/><br/> <br/> <html:submit><bean:message key="label.submit" /></html:submit> <html:reset><bean:message key="label.reset" /></html:reset> </html:form> </body> </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="textForm" type="org.r4r.struts.TextForm"/> </form-beans> <global-exceptions /> <global-forwards /> <action-mappings > <action path="/text" type="org.apache.struts.actions.ForwardAction" parameter="/index.jsp"/> <action path="/textAction" type="org.r4r.struts.TextAction" name="textForm" input="/index.jsp"> <forward name="success" path="/success.jsp"/> </action> </action-mappings> <message-resources parameter="org.r4r.struts.ApplicationResources" /> </struts-config>TextForm.javapackage org.r4r.struts; import org.apache.struts.action.ActionForm; @SuppressWarnings("serial") public class TextForm extends ActionForm { private String name; private String course; private String college; private String phone; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getCourse() { return course; } public void setCourse(String course) { this.course = course; } public String getCollege() { return college; } public void setCollege(String college) { this.college = college; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } }TextAction.javapackage 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 TextAction extends Action { public ActionForward execute(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception{ @SuppressWarnings("unused") TextForm passwordForm=(TextForm)form; return mapping.findForward("success"); } }ApplicationResources.properties# Resources for parameter 'org.r4r.struts.ApplicationResources' # Project Struts1.3_TextTagExample #label message label.name = User Name label.course = Course Name label.college = College Name label.phone = Phone No label.submit = Submit label.reset = Resetsuccess.jsp<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> <html> <head> <title>Struts html:text tag example</title> </head> <body> <h3>Struts html:text tag Example</h3> <h4>User Name:-<bean:write name="textForm" property="name" /></h4> <h4>Course:-<bean:write name="textForm" property="course" /></h4> <h4>College Name:-<bean:write name="textForm" property="college" /></h4> <h4>Phone No:-<bean:write name="textForm" property="phone" /></h4> </body> </html>Output
Previous | Home | Next |