Write A Login ActionForm

Write A Login ActionForm

Previous Home Next

 

You had made a struts Input JSP View in previous section. To gather data from struts Input View Struts Frameworks provides org.apache.struts.action.ActionForm class. With by use this class we have to create a subclass which used to gather all data coming from input view.Here In this subclass, We can validate data input form (we will discuss it later) and also define reset method.


 The following code is appropriate subclass of ActionForm of Input JSP View (Which we had discuss in our previous topic).In this first we have create package then import all required resources(packages ). Make a subclass with the name LoginForm.Declare all variables (variables name must be same as property name as in Input JSP View). Create getter/setter method and finally create reset method .In reset method set all variables null. Configure ActionForm in struts-config.xml file.Like Here name attribute value is lookup value through which action controller lookup the appropriate subclass of ActionForm.type attribute is full qualified name of subclass of ActionForm.We can configure any number of ActionForm in struts-config.xml. 

LoginForm.java

package com.r4r.struts;

import org.apache.struts.action.ActionForm;
@SuppressWarnings("serial")
public class LoginForm extends ActionForm {
	private String name;
	private String password;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}	
}


Previous Home Next