Configure ActionForm into struts-config.xml

Configure ActionForm into struts-config.xml

Previous Home Next

 

In struts-config.xml,The form bean definition section contains one or more entries for each ActionForm but each bean have a unique logical name. The type represent the fully qualified class name of this ActionForm.

 In action mapping section ,Name attibutes define the logical name of the Form bean. Action Mapping associated the Actual ActionForm. ActionMapping is found by looking in the Form-bean definition section for a form-bean with the matching name.

In this example ,Action Mapping associated the LoginForm that is found by looking in the Form-bean definition .

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;
	}
}

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="loginForm" type="com.r4r.struts.LoginForm"/>
</form-beans>
<global-exceptions />
<global-forwards>
<forward name="login" path="/login.do"/>
</global-forwards>
<action-mappings>
<action path="/login" type="com.r4r.struts.LoginAction" name="loginForm">
<forward name="success" path="/success.jsp"/>
<forward name="error" path="/error.jsp"/>
</action>
</action-mappings>
<message-resources parameter="com.r4r.struts.ApplicationResources"/>
</struts-config> 


Previous Home Next