Extract 100+ input data from a POST'ed form with jsp: any better approaches?

后端 未结 1 2041
北荒
北荒 2021-01-15 04:45

A servlet that I am writing needs to access all 100+ POST parameters (filled in by a form): the parameters are different by type (text, option, select, etc.). With the param

1条回答
  •  礼貌的吻别
    2021-01-15 04:53

    If you make sure that the entity bean property names match exactly the request parameter names, then you could use BeanUtils#populate() of Apache Commons BeanUtils for that.

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

    That's all.

    To get a step further, you can adopt a MVC framework which transparently maps request parameters to bean properties (the model) for you based on how the view is composed (even along with transparent conversion, validation and invoking bean action methods!), such as JSF or Spring MVC.

    0 讨论(0)
提交回复
热议问题