gstackoverflow
gstackoverflow

Reputation: 37078

How to access to object method called "get" on jsp to avoid using scriplets?

I have following library class:

public class LibClass{
    public int get(int a, String b) {
        ....
        return 12;
    }
}

How to invoke following method on jsp?

I want to render 12 on jsp.

P.S.

I have restriction that I cannot use scriplets

Upvotes: 1

Views: 503

Answers (2)

Sharp Edge
Sharp Edge

Reputation: 4192

There is another way. You can make a simple Bean which gets this value

 public String getDATE(){

 String Date = String.valueOf(new java.util.Date());
  return Date;
 }

and then call the above method with the following jsp tag

<jsp:useBean id="now" class="beans.PropertyBean" />
<jsp:getProperty name="now" property="DATE" />

you can use anything returned from the bean, In above snippet 'PropertyBean' is the name of my custom bean class. Hope this answers your question.

Upvotes: 0

Suresh Atta
Suresh Atta

Reputation: 122018

You can do that using expression language. For ex

Assuming that you've a ${instance} in the scope

${instance.get(1,"test")}

Upvotes: 2

Related Questions