This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes jsp:setProperty name= Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp:setProperty name="" property="*" equiv for servlet" Watch "jsp:setProperty name="" property="*" equiv for servlet" New topic
Author

jsp:setProperty name="" property="*" equiv for servlet

Justin Chu
Ranch Hand

Joined: Apr 19, 2002
Posts: 209
    
    1
I'm quite sure there's no equivalent code that I can use for servlets.
Are there any easy alternatives? Did anyone manage to decompile the tag code?
Chu
[ June 19, 2002: Message edited by: Chu Tan ]
Justin Chu
Ranch Hand

Joined: Apr 19, 2002
Posts: 209
    
    1
I've written this method to put in the "bean" class. (not tested yet) Just to see if anyone has any comments.

[ June 19, 2002: Message edited by: Chu Tan ]
Bhushan Jawle
Ranch Hand

Joined: Nov 22, 2001
Posts: 249
Having inspired by you idea I have a working(tested) code for servlet equivalent of jsp:setProperty name="" property="*"
/**
* This method populates bean object properties from the request
* parameters having same name. Hence it is equivalent of
* <jsp:setProperty name="beanId" property="*"/>
* @param HttpRequest The servlet request containing parameters
* @param Bean object implementing Serializable
*/

public void populateBean(HttpServletRequest request, Serializable beanToBePopulated)
{
Enumeration enum = request.getParameterNames();
String name;
String[] values;
int i = 0;
while (enum.hasMoreElements())
{
name = (String)enum.nextElement();
values = request.getParameterValues(name);
for (i = 0; i < values.length; i++)
{
try
{
Class beanClass = beanToBePopulated.getClass();
Class fieldClass = beanClass.getDeclaredField(name).getType();
String methodName = "set" + name.substring(0, 1).toUpperCase() + name.substring(1);
Method method = beanClass.getMethod(methodName, new Class[]{fieldClass});
method.invoke(beanToBePopulated, new Object[]{values[i]});
}
catch (NoSuchMethodException e){}
catch (java.lang.reflect.InvocationTargetException e){}
catch (IllegalAccessException e){}
catch (NoSuchFieldException e){}
}
}
}
Any comments are welcome.
Regards,
Bhushan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp:setProperty name="" property="*" equiv for servlet
 
Similar Threads
EAR/WAR/JAR Architecture
B&S: Passed 373/400
EJB bean implementing local/remote interfaces
How to implement: java code --> exe on Windows?
Why a JFrame's appearence on Windows is different from its on Linux?