Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Weird behaviour of java code inside JSP for introspection

843836Jun 22 2004 — edited Jun 25 2004
I have some lines of java code that bahave differently if they are executed from Tomcat (inside a JSP) or
from java putting them in a class with its main function.
I noticed that trying to figure out a problem with a bean:

public class ProvaBean {

public ProvaBean(){}

public void setElem(int i){ ... }

public Object getElem(){}

}

In a bean you can have a set/get method without the corresponding get/set so I supposed it was correct also if there is an incongruence in their type !?
Now it comes the tricky part.
I executed the following code from java passing a reference to an instance of ProvaBean:

Method method = null;
Class type = null;
BeanInfo info = Introspector.getBeanInfo(bean.getClass());
if(info != null)
{
PropertyDescriptor pd[] = info.getPropertyDescriptors();
for(int i = 0; i < pd.length; i++){
System.out.println(pd.getName());
method = pd[i].getWriteMethod();
type = pd[i].getPropertyType();
if (type != null)
System.out.println("Tipo = " + type.getName());
if (method != null) {
System.out.println("Method = " + method.getName());
Class[] parametri = method.getParameterTypes();
for (int y = 0 ; y < parametri.length; y++)
System.out.println("--->" + parametri[y].getName());
}
}
}


The result was:
elem
Tipo = int
Method = setElem
--->int

Executing the same code inside a JSP I got:

elem
Tipo = Object

So inside a JSP the set method cannot be found by introspection !

Any idea ?
Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 23 2004
Added on Jun 22 2004
1 comment
61 views