[標(biāo)題]:EL函數(shù)的使用
[時(shí)間]:2009-4-3
[摘要]:簡(jiǎn)單的EL函數(shù)示例。
[關(guān)鍵字]:EL,function,tld,jsp,jstl,標(biāo)簽
[平臺(tái)]:Tomcat6
[作者]:Winty (wintys@gmail.com)
[正文]:
Step1:
編寫(xiě)所需要的類(lèi),將編譯生成的el.ELFunction復(fù)制到WEB-INF/中。
package el;
public class ELFunction{
public static String toUpper(String str){
return str.toUpperCase();
}
}
注意,用于EL中的函數(shù)需定義為static,不然會(huì)出錯(cuò)。
Step2:
在WEB-INF/tlds中添加el.tld,內(nèi)容如下 :
<?xml version = '1.0' encoding = 'GBK'?>
<taglib 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" xmlns="http://java.sun.com/xml/ns/j2ee">
<tlib-version>1.0</tlib-version>
<short-name>fc</short-name>
<uri>http://wintys/el</uri>
<function>
<name>toUpper</name>
<function-class>el.ELFunction</function-class>
<function-signature>
java.lang.String toUpper(java.lang.String)
</function-signature>
</function>
</taglib>
Step3:
在WEB-INF/web.xml中添加:
<taglib>
<taglib-uri>http://wintys/el</taglib-uri>
<taglib-location>/WEB-INF/tlds/el.tld</taglib-location>
</taglib>
Step4:
編寫(xiě)測(cè)試頁(yè)面ELFunction.jsp:
<%@page contentType="text/html;charset=GBK" %>
<%@taglib uri="http://wintys/el" prefix="myfun" %>
EL Function:<br />
${myfun:toUpper("abcde")}
重啟Tomcat后運(yùn)行ELFunction.jsp即可得到結(jié)果。
posted on 2009-04-03 21:29
天堂露珠 閱讀(1362)
評(píng)論(0) 編輯 收藏 所屬分類(lèi):
Java