views:

282

answers:

2

Is there an equivalent to:

<jsp:setProperty name="beanName" property="*"/>

for servlets?

Something that will auto-populate the bean from inside a servlet using the request parameters? I'm refactoring a JSP-only application and would like to move some of the code to servlets. For a bunch of tragic reasons, we are not able (right now) to use any frameworks to make this easier.

+4  A: 

Can you use external libraries? If so, Commons BeanUtils would help you a lot.

Update: Now that you've confirmed you can use this approach:
The method you're looking for is BeanUtils.populate(). There is an example here (chapter 4.2) on how to use it to map request parameters.

ChssPly76
I can - so I'll check this out.
Jibba
Thanks - this works perfectly.
Jibba
+2  A: 

You can use reflection to do it, but there is nothing there from you out of the box. It would be pretty easy to write a little helper object to do using reflection

mkoryak