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]
# 1
why don't you just use netbeans, right click -> view servletit will automatically show you the equivalent servlet of your jsp
shuinia at 2007-7-14 22:54:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
!!!!really?i am using eclipse and I guess it doesnt have this feature.thanks, i will have a netbean to try this out.
netangela at 2007-7-14 22:54:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

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

evnafetsa at 2007-7-14 22:54:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

> !!!!

> 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.

Madathil_Prasada at 2007-7-14 22:54:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
evnafets, sorry - dint look at your post :)ram.
Madathil_Prasada at 2007-7-14 22:54:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
thanks!test.setField1(request.getParameter("field1"));test.setField2(request.getParameter("field2"));is working!
netangela at 2007-7-14 22:54:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
hey thanks a lot,I knew that I came to the right place.able to find out the answer within 1 hour since i post the question.
netangela at 2007-7-14 22:54:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
> 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?
evnafetsa at 2007-7-14 22:54:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

> > 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.

Madathil_Prasada at 2007-7-14 22:54:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...