need help in converting jsp code to servlet code, thanks
<jsp:useBean id="Test" type="IntegrationObject.Test" class="IntegrationObject.Test">
<jsp:setProperty name="Test" property="*" />
</jsp:useBean>
I am doing HATS and retrieving data from macro from green screen macro.
so the above is the syntax to pass the value in and get the result.
I am thinking to convert it to servlet, so the below is the one.
IntegrationObject.Test test=new IntegrationObject.Test();
test.doHPTransaction(request,response);
it works except passing the value inside.
it will not pass the parameter from request to the macro.
so I wonder how to convert "<jsp:setProperty name="Test" property="*" />" to servlet form?
thanks.
[744 byte] By [
netangela] at [2007-10-3 4:49:52]

The manual way to do it would be
test.setField1(request.getParameter("field1"));
test.setField2(request.getParameter("field2"));
There is a library in the jakarta commons to help with just this situation.
[url http://jakarta.apache.org/commons/beanutils/] Commons BeanUtils[/url]
The specific method you would be after is BeanUtils.populate
It would be used something like this:
IntegrationObject.Test test=new IntegrationObject.Test();
BeanUtils.populate(test, request.getParameterMap());
Hope this helps,
evnafets
> !!!!
> really?
> i am using eclipse and I guess it doesnt have this
> feature.
> thanks, i will have a netbean to try this out.
You dont require eclipse or netbeans or this - your server will have the generated Servlet files stored somewhere in its installation directory. For tomcat this directory is by default the "work" directory unless configured otherwise.
That said, you can easily enough code it yourself (& learn something along the way as a bonus :)
<jsp:setProperty name = "Test" property = "*"/>
The setPropety above looks at the request parameters and for each request param calls a corresponding setXXX() on the bean where 'XXX' is the name of the request param. It passes in the value associated with the request param.
So if the request is like below
?id=10&name=Jack&manager=true
then setProperty calls
setId(10);
setName("Jack");
setManager(true);
on the bean.
So the challenge here is
1. To dynamically call a method on the bean object based on the request param.
2. To convert the String value of the param to the appropriate primitive data type before invoking the method.
You can achieve both of these by reflection ([url http://java.sun.com/docs/books/tutorial/reflect/class/getMethods.html]tutorial[/url]).
Apache has a BeanUtils library which simplifies the reflection task for you and there is an [url http://jakarta.apache.org/commons/beanutils/commons-beanutils-1.7.0/docs/api/org/apache/commons/beanutils/package-summary.html#package_description] example here on usage[/url]. (look under the heading DataType Conversions).
ram.
> > evnafets, sorry - dint look at your post :)
> >
> > ram.
>
> Well considering we managed to post within the same
> minute, I'm not entirely surprised ;-)
>
> Great minds think alike eh?
Thanks :), I am flattered, but to be entirely honest, you are in a different league, a higher plane & that's not flattery, just plain fact :)
ram.