In the previous blog titled "jstl and El basics", we introduced jstl and El basics. In this blog, We will write our own jstl functions and give a simple greeting.
Myfunction. Java
Package COM. tgb. jstl;/******** greet someone * @ author administrator **/public class myfunctions {public static string sayhello (string name) {return ("hello" + name );}}
Modify configuration file
<?xml version="1.0" encoding="UTF-8" ?><taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0"> <description>function library</description> <display-name>my functions</display-name> <tlib-version>1.1</tlib-version> <short-name>mf</short-name> <uri>http://java.sun.com/jsp/jstl/myfn</uri> <function> <description> Tests if an input string contains the specified substring. </description> <name>say</name> <function-class>com.tgb.jstl.MyFunctions</function-class> <function-signature>java.lang.String sayHello(java.lang.String)</function-signature> </function> </taglib>
JSP page reference
<%@ taglib uri="http://java.sun.com/jsp/jstl/myfn" prefix="mf" %>
Call
Greetings: $ {MF: Say ("sansan ")}
Combined with the previous blog, we can see the powerful custom functions of jstl, and play the role of tags to the extreme.
For more DRP blogs, visit DRP project summary.