javaservletsreflectionjavabeans

Easiest way to populate a bean using servlet params


without using any big web framework (just servlets), do you know a ready to use small library that can populate my bean properties from the params of an http request?


Solution

  • You could take a look at Commons Beanutils, it has a whole bunch of methods for populating beans (including nested beans):

    http://commons.apache.org/beanutils/

    The method, in particular, that you want to look at is populate in BeanUtilsBean:

    public void populate(Object bean,
                         Map properties)
    

    More info here:

    http://commons.apache.org/beanutils/api/org/apache/commons/beanutils/BeanUtilsBean.html#populate%28java.lang.Object,%20java.util.Map%29