dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Advanced
Feb 20, 2001

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Middle Tier Code Optimization With Java Reflection Package


In Web based programming, we usually check querystring parameters in middle tier java objects and do tedious, if not long, checks via if/else, to perform appropriate action or instantiate classes. A good workaround is to use Java reflection (java.lang.reflect). Class methods, like getMethods[] or getFields[], invoke particular methods based on http querystring params, like Method.invoke(...).

Here is an example java codelet:
 
//get Class info of your object say 'a'
Class c = a.getClass();

//to dynamically get Object/fields based on HTTP 
querystring namevalue pair, say 'requestParam'

Field f = c.getField(requestParam);

// or else 'invoke' a particular method vis a vis 
requestParam

Method[] theMethods = c.getMethods();
String result = (String) theMethods[0].invoke
(requestParam, null);
Khurram Zaheer
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date