JSP自定义EL函数
来源:互联网 发布:淘宝商家联系方式 编辑:程序博客网 时间:2024/05/17 08:57
EL函数:必须要放在EL表达式里
定义EL函数的步骤:
1: public 构造方法
2. 定义特定的static函数
3. 在标记库描述文件(tld)中描述这个函数
4. 在web.xml部署次tld文件
注:如果打成jar包放在build path 把tld文件放在包里就不要配置了
5. 在JSP文件中用taglib指令定义函数的命名空间
Java:
public class MoneyFunc {
public MoneyFunc(){}
/**
* 返回带,号的金额
* @param amount
* @return
*/
public static String getFormatStr(String amount)
{
String ret = "";
try {
ret = NumberFormat.getCurrencyInstance().format(Double.valueOf(amount)).replaceAll("¥", "");
} catch (Exception e) {
}
return ret;
}
}
money.tld:
<?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 web-jsptaglibrary_2_0.xsd"
version="2.0">
<tlib-version>1.1</tlib-version>
<short-name>money</short-name>
<uri>/money</uri>
<function>
<description>返回带,号的金额</description>
<name>getFormatStr</name>
<function-class>org.xxxxx.MoneyFunc</function-class>
<function-signature>
java.lang.String getFormatStr(java.lang.String)
</function-signature>
</function>
</taglib>
web.xml:
<jsp-config>
<taglib>
<taglib-uri>/WEB-INF/tld/money.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/money.tld</taglib-location>
</taglib>
</jsp-config>
jsp:
<%@ taglib uri="/WEB-INF/tld/money.tld" prefix="money" %>
${money:getFormatStr(ent.bfamount)}
//上面有一步是多余的 的。。。。
详情看李刚疯狂的那本书
- JSP自定义EL函数
- JSP自定义EL函数
- JSP自定义1-自定义EL函数
- JSP EL 自定义函数的使用
- jsp自定义标签tag EL函数
- 如何自定义EL函数
- EL自定义函数
- el自定义函数
- EL自定义函数
- 自定义EL函数
- EL表达式-自定义函数
- EL表达式-自定义函数
- 自定义el函数
- EL自定义函数
- 自定义EL函数
- EL自定义函数
- EL自定义函数
- 自定义EL函数
- VMware 下Fedora9安装VMware tools记录
- sql统计查询
- 情伤
- MIME协议发送邮件
- 傻人?
- JSP自定义EL函数
- OGRE demo分析
- matlab错误:Subscript indices must either be real positive integers or logicals.
- 伤情
- Ghost使用图解
- jquery ajax loading效果
- 客户端和服务端通讯的N种方式(一)
- 搞活动送的书《社会学》到了
- sizeof class or struct