JSP 2.0 EL and Functions

In my last project I need to call some utility methods from my JSP to manipulate model data. I didn't wanted to use JSP scriplets within the JSP, so the solution was to use utility method via JSP2.0 EL feature.

Approach I folowed was:
1. Declare function in a tag library descriptor.




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">

Image Utility functions
Image Utility Tag Library
1.0
ImageUtility

getImagePath
com.til.hk.utils.CommonUtils
java.lang.String getImagePath(java.lang.String, java.lang.String)


getRelativeImagePath
com.til.hk.utils.CommonUtils
java.lang.String getImagePath(java.lang.String)




2. Store TLD under WEB-INF directory (/WEB-INF/tld/)
3. Specify the function's prefix and the library's Uniform Resource Identifier (URI) in JSP file

<%@ taglib uri="/WEB-INF/tld/ImageManip.tld" prefix="image"%>

0 comments: