JSP: Passing more than one param into method

D

Dave

If I have instantiated a controller class in a JSP page (using
<jsp:useBean...>), can I call methods which have more than one parameter
from within that JSP page?

The reason I ask is that AIUI, methods with more than one parameter do not
meet the JavaBean spec.
 
M

Manish Pandit

Hi,

You cannot use <jsp:setProperty> for methods that accept more than 1
param, as the value attribute only accepts 1 literal. Besides, as you
correctly pointed out - such methods do not follow the JavaBeans
standard.

-cheers,
Manish
 
D

Dave

Manish Pandit said:
Hi,

You cannot use <jsp:setProperty> for methods that accept more than 1
param, as the value attribute only accepts 1 literal. Besides, as you
correctly pointed out - such methods do not follow the JavaBeans
standard.

Could I use something like...?

<jsp:useBean class="TestName" id="objx" scope="page" >

<%
objx.testMethod(param1, param2)
%>
 
M

Manish Pandit

<%
objx.testMethod(param1, param2)
%>

Yes - I thought you were refering to setting properties in the original
post. The above will work assuming param1 and param2 are either
page-scoped, or are java variables you delcared somewhere in a
scriptlet.

-cheers,
Manish
 
D

Dave

Manish Pandit said:
Yes - I thought you were refering to setting properties in the original
post. The above will work assuming param1 and param2 are either
page-scoped, or are java variables you delcared somewhere in a
scriptlet.

Thanks.

One last question - do the objects instantiated in a JSP page *need* to
adhere to the JavaBean convention or can they be any Java object at all?
 
M

Manish Pandit

One last question - do the objects instantiated in a JSP page *need* to
adhere to the JavaBean convention or can they be any Java object at all?

They can be any java object, but if you want to set/get properties
using jsp:setProperty and jsp:setProperty, they have to have the
property setters/getters per JavaBeans specification.

If you intend on using jsp:useBean to instantiate an object and later
use it in a *scriptlet*, you are free to use any object. However, in my
opinion, the JSP should not be dealing with functionality - all such
cases belong at the controller.

-cheers,
Manish
 
D

Dave

Manish Pandit said:
They can be any java object, but if you want to set/get properties
using jsp:setProperty and jsp:setProperty, they have to have the
property setters/getters per JavaBeans specification.

If you intend on using jsp:useBean to instantiate an object and later
use it in a *scriptlet*, you are free to use any object. However, in my
opinion, the JSP should not be dealing with functionality - all such
cases belong at the controller.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top