CHAPTER 3: Best Practices in Java EE Web Development 127
11.com.apress.elfunction.Now
12.
13.
14.String now()
15.
16.
17.
18.
Line7: Line 7 is the URI of the function that will be used in the taglib directive in
the JSP page.
Lines 8 to 17: These lines specify the Java method that will be invoked with the
signature and the Java class in which this method is defined.
A Java method can be called from JSP using EL in the following manner: ${prefix:function-name).
The namespace prefix is declared by using the taglib directive in the JSP page. Listing 3-33 shows
the JSP code.
Listing 3-33. Invoking an EL Function in JSP
1.<%@ taglib prefix="elf" uri="elFunction"%>
2.
3.
4.
5.
6.
Line 1: Line 1 is a taglib directive with the prefix elf and a URI. The URI is
defined in the tag library descriptor.
Line 4: This uses the prefix elf and invokes the function. This function name is
defined in the tag library description.
You can create this application based on the first JSP application we created in Chapter 2. When
this application is run (http://localhost:8080/elFunctions/elTest.jsp), it gives the output shown
in Figure 3-8.