?
Solved

Setting bean properties in servlet

Posted on 2003-03-17
5
Medium Priority
?
383 Views
Last Modified: 2011-09-20
In a jsp page you can set all of a beans properties at once using something like
<jsp:setProperty name="bean"
{
   property="*"
}
/>

Is there an equivalent way to do this from a servlet or do you have to set each property individually?
0
Comment
Question by:woolardc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:allahabad
ID: 8156729
There is no <jsp:setProperty > and <jsp:getProperty > in Servlet. You will have to write set/get method .
0
 
LVL 92

Expert Comment

by:objects
ID: 8156777
As allahabad states there is no supplied method in a servlet to provide this. There is however no reason why you could not provide your own implementation of JspRuntimeLibrary.introspect().
0
 

Author Comment

by:woolardc
ID: 8156812
So am I right in assuming that for a bean with 10 properties I have to write out set_____() for each one and there is no more efficient way?
0
 
LVL 3

Expert Comment

by:allahabad
ID: 8156823
You can have a method that takes all 10 parameters and set them in one call.
0
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 8156845
You could use reflection to write a generic method which attempts to match request parameters with bean set methods (similiar to how jsp does it).

It's probably not as simple as having 10 set calls as you need to only set the parameters that actually exist in the request.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Summer 2017 Scholarship Winners have been announced!
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question