javax.servlet.ServletException: BeanUtils.populate

javax.servlet.ServletException: BeanUtils.populate

Root Cause:

java.lang.IllegalArgumentException: argument type mismatch
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


Fallowings are may be the reason for the above exception
1) The action attribute of an tag must match exactly the path attribute of the action definition in the struts-config.xml file. This is how Struts associates the ActionForm bean with the action.

2) This error usually occurs when you have specified a form name that does not exist in your tag. For example, you specific and ‘myForm’ is not the name of a form associated with myAction in the struts-config file

3) You get this message when Struts is unable to map the data in the HTML form to the properties in your ActionForm bean. Make sure each of the properties on your bean is either a String or a Boolean. Do you have any properties of type java.util.Date or other objects? That might cause this error. Also check to see that you have public getters and setter for each of your properties.

Struts Internationalization Example

web.xml :

<?xml version=”1.0″ encoding=”Shift_JIS”?>

<!DOCTYPE web-app
PUBLIC “-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN””&gt;










<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE struts-config PUBLIC “-//Apache Software Foundation//DTD Struts Configuration 1.2//EN” “”&gt;
<form-bean name=”loginform” type=”org.apache.struts.validator.DynaValidatorForm”>
<form-property name=”username” type=”java.lang.String”></form-property>
<form-property name=”password” type=”java.lang.String”></form-property>
<action path=”/login” type=”in.javatutorials.actions.LoginAction” name=”loginform” validate=”true” input=”/login.jsp”>
<forward name=”success” path=”/welcome.jsp”></forward>
<forward name=”failure” path=”/login.jsp”></forward>
<controller locale=”true” processorClass=”org.apache.struts.tiles.TilesRequestProcessor”/>
<message-resources parameter=”ApplicationResources”/>
<plug-in className=”org.apache.struts.tiles.TilesPlugin”>
<set-property property=”definitions-config” value=”/WEB-INF/tiles-defs.xml”/>
<set-property property=”moduleAware” value=”true”/>
<plug-in className=”org.apache.struts.validator.ValidatorPlugIn”>
<set-property property=”pathnames” value=”/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml”/>

login.jsp :

<%@ taglib uri=”/tags/struts-bean” prefix=”bean” %>
<%@ taglib uri=”/tags/struts-logic” prefix=”logic” %>
<%@ taglib uri=”/tags/struts-html” prefix=”html” %>
<%@ taglib uri=”/tags/struts-nested” prefix=”nested” %>

<meta http-equiv=”Content-Type” content=”text/html; charset=Cp1252″/>
<body bgcolor=”yellow”>
<bean:message key=”welcome.message”/>
<html:form method=”POST” action=”login”>
<bean:message key=”username”/><html:text property=”username”></html:text><br><br>
<bean:message key=”password”/><html:text property=”password”></html:text><br><br>
<html:submit><bean:message key=”register.submit”/></html:submit>

 package in.javatutorials.actions;
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;
import org.apache.struts.validator.DynaValidatorForm;

* LoginAction Class

public class LoginAction extends Action {
* Action class execute method

public ActionForward execute(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest request,HttpServletResponse response)throws Exception{

String responseKey=”failure”;
DynaValidatorForm dynaValidatorForm=(DynaValidatorForm) actionForm;
String user=(String)dynaValidatorForm.get(“username”);
String pwd=(String)dynaValidatorForm.get(“password”);

return actionMapping.findForward(responseKey);


welcome.jsp :

<%@ page contentType=”text/html; charset=Cp1252″ %>
<%@ taglib uri=”/tags/struts-bean” prefix=”bean” %>
<%@ taglib uri=”/tags/struts-logic” prefix=”logic” %>
<%@ taglib uri=”/tags/struts-html” prefix=”html” %>
<%@ taglib uri=”/tags/struts-nested” prefix=”nested” %>

<meta http-equiv=”Content-Type” content=”text/html; charset=Cp1252″/>
<body bgcolor=”green”>
<h1><bean:message key=”welcome”/></h1>
</html:html> :

welcome.message=Dare if benevenuato all aperatoreitaliano(in english:welcome to italian user)
welcome=<b>Dare if benevenuato all aperatoreitaliano</b>
username=<b>nome de operatore</b>
password=<b>parola de ordine</b>
errors.required=<li><i>if compo di{0}non puo essere vuoto</i></li>
errors.minlength=<li><i>la {0}non puo essere vuoto {2} carreteri.</i></li> :

welcome.message = welcome to english user
welcome=<b>Hello english user welcome to our website</b>
errors.required=<li><i>{0}field cannot be empty.</i></li>
errors.minlength=<li><i>{0}cannot be lessthan {2} charecters.</i></li>

What are the differences between DispatchAction and LookupDispatchAction in Struts Framework?

Dispatch Action
It’s a parent class of  LookupDispatchAction
Subclass of Dispatch Action
DispatchAction provides a mechanism for grouping a set of related functions into asingle action, thus eliminating the need to create separate actions for each function.
An abstract Action that dispatches to the subclass mapped executes method. This is useful in cases where an HTML form has multiple submit buttons with the same name. The button name is specified by the parameter property of the corresponding ActionMapping.
If not using Internalization functionality then dispatch action is more useful.
Lookup Dispatch Action is useful when we are using Internalization functionality
DispatchAction selects the method to execute depending on the request parameter valuewhich is configured in the xml file.
LookupDispatchAction looks into the resource bundle file and find out the corresponding key name. We can map this key name to a method name by overriding the getKeyMethodMap() method. 
DispatchAction is not useful for I18N
LookupDispatchAction is used for I18N
Find the DispatchAction Example here
Others Posts:

What design patterns are used in Struts 1.X?

Struts is based on model 2 MVC (Model-View-Controller) architecture. Struts controller uses the command design pattern and the action classes use the adapter design pattern. The process() method of the RequestProcessor uses the template method design pattern. Struts also implement the following J2EE design patterns.

  • Service to Worker
  • Dispatcher View
  • Composite View (Struts Tiles)
  • Front Controller
  • View Helper
  • Synchronizer Token

Struts MVC

Struts is MVC based framework developed by Apache. Framework generally provides the basic functionality for a project. Struts provides the set of Action classes, set of tag-libraries, set of Form beans and etc.

Struts combines the most of the design patterns in to a single framework. Struts implements the Single-ton design pattern, Delegate design pattern, Factory Design pattern, Chain of responsibilities.

Struts is Strongly Model View Controller (MVC)based framework MVC fallows the three tier architecture. The model, view and controllers regarding to the Struts are explained as fallows.


View is used to show something to user. Struts allows to use htmls, jsps as view components. To develop the more friendly views struts provided the set of tag libraries. You can download these libraries from the apache site and you can use those into your view components. The set of tag libraries are

struts-html : These tags are replacement of normal html tags. The struts html tags are binds with the form bean properties.

Ex: <html:text property=”userName” />

tag replaces the normal html tag like

<input type=”text” name=”userName” />

struts-bean : These tags are replacement for the jsp action tags. The bean properties are defined with this tags, you can get the bean properties using struts-bean tags.

Ex: <bean:define id=”tempVar” value=”10” />

Above tag defines a variable as ‘tempVar’ and assign 10 to it as string value.

<bean:write name=”Employee” property=”empId” />

Above tag get the value of empId from the Employee form bean.

Struts-logic: These tags are used to write the logical operations. To validate the if conditions or equals conditions you can use these tags.

Ex: <logic:equal name=”empId” value=”100” >Adimin</logic:equal>

Admin is displayed when the empId equals to 100 only.

To get the for loop type iterations you can use the <logic:iterate /> tag.

struts-nested: To display the group of objects you can use the nested tags.

You can implement most of the functionality of above three tags with the nested tags.

Inplace of <bean:write /> you have <nested:write /> and so on…….


Business logic and persistence logic (database dependent logic) will be developed in Model. In struts you can use normal Java beans, DTOs, Dos as models. You can develop the Model layer using other tools also. Struts allows to use Hibernate, spring in the model layer.


Controller is most important concept in the Struts 1.3. In struts ActionServlet acts as Front controller. Each and every request must passes through the ActionServlet. You can change the ActionServlet functionality by extending ActionServlet to your own class.

RequestProcessor class also acts as the controller to process the request. In struts 1.3 Request processor is the ComposableRequestProcessor. It has processXXX() methods. These methods are controls the execution of action classes, controlling of form beans ..etc.

Actions, Dispatch actions, Action Forms , Validator forms ..etc all are come under the controller.

Difference Normal HTML tags and Struts HTML tags

Apache struts provided the struts html tags as the replacement of normal html tags for the Jsps. These Struts html tags are directly bind to the form bean using ActionForm where as normal html tags cannot bind with form beans. HTML tags are static but Struts tags are Dynamic (At the run-time struts tags are called)

But coming to performance half of the code in struts tags is pre-compiled one. If we use normal html tags web container has to load the jsp from the scratch. Where as struts tags loads with the pre-compiled code. So that struts tags improves the performance.