EL Functions:
Very simple used to invoke any functions with names.......
For Ex:
create a class as below:com.fun.Message
package com.fun;
/*
* A class Which contains the user defined funcion sayHello
*/
public class Message{
public static String sayHello(){
return "hello!!";
}
}
Keep this .class under /WEB-INF/classes/com/fun/Message.class
Then we have to create TLD file which describes your functions :
myfucntions.tld:
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.1</jsp-version>
<function>
<name>hello</name>
<function-class>com.fun.Message</function-class>
<function-signature>java.lang.String sayHello()</function-signature>
</function>
<function>
<name>rand</name>
<function-class>java.lang.Math</function-class>
<function-signature>long random()</function-signature>
</function>
<function>
<name>absolute</name>
<function-class>java.lang.Math</function-class>
<function-signature>int abs(int)</function-signature>
</function>
</taglib>
You can observer this TLD is describing some predefined functions of java.lang.Math class also.
Save this file as " myfunctions.tld" keep this under /WEB-INF folder of your application.
"name" tag in function is necessary with that name only user is going to call the functions.
Then at last create your jsp:
<%@page isELIgnored="false" %>
<%@taglib uri="/WEB-INF/myfunctions.tld" prefix="f" %>
${f:hello()}
${f:rand()}
${f:abso lute(10)}
Rocking
Shyamala
No comments:
Post a Comment