?
Solved

Setting bean properties in servlet

Posted on 2003-03-17
5
Medium Priority
?
386 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
  • 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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

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

The following information will get you familiar with your new DV server, including the (mt) Account Center, the Plesk Control Panel, our world-renowned support department and the rest of the (mt) tools that come with your new service.
This article explains how to use the rsync command to create backups and sync data across hosts. Rsync is a very useful command that is often used to copy data, make backups, migrate hosts, and bridge the gap between site staging and production envi…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Suggested Courses

616 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