ITeye博客

自定义标签

kidd · 2009-02-16 16:23 · Markdown

web.xml代码:下

function.tld代码:下

<taglib version="2.0" 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"> 处理EL转换的自定义函数 1.0 my-function /my-function

<function>
	<description>获取性别(男/女)</description>
	<name>getSex</name>
	<function-class>com.util.MyFunction</function-class>
	<function-signature>
		java.lang.String getSex( java.lang.String )
	</function-signature>
</function>

MyFunction.java代码:下 (可在MyFunction类中根据需要写如自己的方法)

public class MyFunction { public static String getSex(String sex) { return ("M".equals(sex) ? "男" : "女"); } }

test.jsp代码:下

<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>

<%@ taglib prefix="my" uri="/my-function"%>

<body>
	<tableborder="1" align="center">
		<tr>
			<th>
				性&nbsp;&nbsp;&nbsp;&nbsp;别
			</th>
			<td>
				<span style="color:red">${my:getSex(sex)}</span>
			</td>
		</tr>

	</table>
</body>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。