Easy way of populating Javabeans based on request parameters

For that Apache Commons BeanUtils is often used.

BeanUtils.populate(bean, request.getParameterMap());

That’s it.

To get a step further, you can adopt a MVC framework which uses Javabeans as models so that you don’t need to worry about them at all, such as JSF or Spring MVC.


Unrelated to the concrete question, using getParameterValues() is clumsy in this specific example. Just use getParameter().

p.setName(request.getParameter("name"));
p.setSecondname(request.getParameter("secondname"));

Leave a Comment