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

511 Views Asked by At

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

2

There are 2 best solutions below

2
On BEST ANSWER

You can do that using expression language. For ex

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

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

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.