JSP: Passing more than one param into method

Discussion in 'Java' started by Dave, Oct 4, 2006.

  1. Dave

    Dave Guest

    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.
     
    Dave, Oct 4, 2006
    #1
    1. Advertising

  2. 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
     
    Manish Pandit, Oct 4, 2006
    #2
    1. Advertising

  3. Dave

    Dave Guest

    "Manish Pandit" <> wrote in message
    news:...
    > 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)
    %>
     
    Dave, Oct 4, 2006
    #3
  4. > <jsp:useBean class="TestName" id="objx" scope="page" >
    >
    > <%
    > 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
     
    Manish Pandit, Oct 4, 2006
    #4
  5. Dave

    Dave Guest

    "Manish Pandit" <> wrote in message
    news:...
    >> <jsp:useBean class="TestName" id="objx" scope="page" >
    >>
    >> <%
    >> 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.


    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?
     
    Dave, Oct 4, 2006
    #5
  6. > 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
     
    Manish Pandit, Oct 4, 2006
    #6
  7. Dave

    Dave Guest

    "Manish Pandit" <> wrote in message
    news:...
    >> 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.


    Thanks.
     
    Dave, Oct 5, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Merciadri Luca
    Replies:
    4
    Views:
    818
  2. Herman
    Replies:
    7
    Views:
    220
    Chris Angelico
    Mar 13, 2012
  3. pradnya
    Replies:
    1
    Views:
    78
    LexNonScripta
    Jan 10, 2008
  4. Steven D'Aprano
    Replies:
    0
    Views:
    99
    Steven D'Aprano
    Dec 23, 2013
  5. Replies:
    3
    Views:
    89
    Gary Herron
    Dec 23, 2013
Loading...

Share This Page