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


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

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