Exception:BeanUtils.populate, argument type mismatch

Source: Internet
Author: User
Tags stack trace apache tomcat


Preface



Before browsing this article, make sure you are experiencing similar problems under similar environment and condition below.



Environment:
Os:windows XP
Language:java 1.5
Framework:struts 1.3
Ide:myeclipse 6.0



Condition:
There is a date input on the JSP page, and the property of the date type is appropriately define in Actionform to get input from the JSP page.



Introduction



This article focuses on the Exception:BeanUtils.populate that define non-string data type may encounter in Struts actionform, argument type mismatch.



Section 1-problem



All you receive on the JSP page is string type input,
If you define the property of the Integer type in Actionform,
Actionform can automatically type conversion the string type input from the JSP page.
The value of the integer type is then assigned to the Define-good integer type by using Set method.



But
If you define the property of Java.util.Date type in Actionform,
When actionform from the JSP page get input, you will encounter the following exception:
HTTP Status-



type Exception



Message



Description The server encountered an internal error () is prevented it from fulfilling this request.



Exception




Javax.servlet.ServletException:javax.servlet.ServletException:BeanUtils.populate
	Org.apache.struts.chain.ComposableRequestProcessor.process (composablerequestprocessor.java:286)
	Org.apache.struts.action.ActionServlet.process (actionservlet.java:1913)
	Org.apache.struts.action.ActionServlet.doPost (actionservlet.java:462)
	Javax.servlet.http.HttpServlet.service (httpservlet.java:710)
	Javax.servlet.http.HttpServlet.service ( httpservlet.java:803)





root Cause


Javax.servlet.ServletException:BeanUtils.populate Org.apache.struts.util.RequestUtils.populate ( requestutils.java:469) Org.apache.struts.chain.commands.servlet.PopulateActionForm.populate ( POPULATEACTIONFORM.JAVA:50) Org.apache.struts.chain.commands.AbstractPopulateActionForm.execute ( ABSTRACTPOPULATEACTIONFORM.JAVA:60) Org.apache.struts.chain.commands.ActionCommandBase.execute (
	actioncommandbase.java:51) Org.apache.commons.chain.impl.ChainBase.execute (chainbase.java:190)
	Org.apache.commons.chain.generic.LookupCommand.execute (lookupcommand.java:304)
	Org.apache.commons.chain.impl.ChainBase.execute (chainbase.java:190)
	Org.apache.struts.chain.ComposableRequestProcessor.process (composablerequestprocessor.java:283)
	Org.apache.struts.action.ActionServlet.process (actionservlet.java:1913) Org.apache.struts.action.ActionServlet.doPost (actionservlet.java:462) Javax.servlet.http.HttpServlet.service (
 httpservlet.java:710) Javax.servlet.http.HttpServlet.service (httpservlet.java:803)





root Cause


Java.lang.IllegalArgumentException:Cannot Invoke Fms.struts.form.testdatetimeform.setlastupdatedatefrom-argument
	Type mismatch Org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod (propertyutilsbean.java:1778)
	Org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty (propertyutilsbean.java:1759)
	Org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty (propertyutilsbean.java:1648)
	Org.apache.commons.beanutils.PropertyUtilsBean.setProperty (propertyutilsbean.java:1677)
	Org.apache.commons.beanutils.BeanUtilsBean.setProperty (beanutilsbean.java:1022)
	Org.apache.commons.beanutils.BeanUtilsBean.populate (beanutilsbean.java:811)
	Org.apache.commons.beanutils.BeanUtils.populate (beanutils.java:298)
	Org.apache.struts.util.RequestUtils.populate (requestutils.java:467)
	Org.apache.struts.chain.commands.servlet.PopulateActionForm.populate (POPULATEACTIONFORM.JAVA:50) Org.apache.struts.chain.commands.AbstractPopulateActionForm.execute (abstractpopulateactionform.java:60) oRg.apache.struts.chain.commands.ActionCommandBase.execute (actioncommandbase.java:51)
	Org.apache.commons.chain.impl.ChainBase.execute (chainbase.java:190)
	Org.apache.commons.chain.generic.LookupCommand.execute (lookupcommand.java:304)
	Org.apache.commons.chain.impl.ChainBase.execute (chainbase.java:190)
	Org.apache.struts.chain.ComposableRequestProcessor.process (composablerequestprocessor.java:283)
	Org.apache.struts.action.ActionServlet.process (actionservlet.java:1913) Org.apache.struts.action.ActionServlet.doPost (actionservlet.java:462) Javax.servlet.http.HttpServlet.service (
 httpservlet.java:710) Javax.servlet.http.HttpServlet.service (httpservlet.java:803)





Note The full stack trace's the root cause is available in the Apache tomcat/6.0.13 logs. 


Apache tomcat/6.0.13



Section 2-reason



The following link raises the same question, whether right or wrong you can look first
Http://topic.csdn.net/t/20050114/11/3725181.html



Here I summarize the actual reason, by my test, actionform in the property does not necessarily have to be a string type, at least for integer, Float, Boolean and so on. It is now found that only date is special, and Struts's actionservlet, after receiving the page request, will call Requestutils.populate to fill in the form. And Requestutils.populate method also call Beanutils.populate, which beanutils.populate to the different data when the value is filled Type is conversion, but Default's actionservlet does not register the corresponding string to Date conversion method, which results in the Acitonform This exception is encountered when define is the date type.



Section 3-solution



1. Implement a custom Actionservlet method and register the conversion function inside. The date type in the
2. Form uses the string type to place the transformation action in action (that is, when the Form->pojo is converted in action), and you can register the type conversion class in the action base class.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.