日期:2014-05-16 浏览次数:20503 次
<?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 http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
    version="2.0">
    
  <description>TEST 1.0 library</description>
  <display-name>TESTTag</display-name>
  <tlib-version>1.0</tlib-version>
  <short-name>test</short-name>
  <uri></uri>
  <!-- 标签 -->
  <tag>
  	<name>listValueName</name>
  	<tag-class>com.test.frame.tags.ListValueTag</tag-class>
  	<body-content>empty</body-content>
  	
  	<attribute>
	  	<name>type</name>
	  	<required>true</required>
  	</attribute>
  	<attribute>
	  	<name>value</name>
	  	<required>true</required>
	  	<rtexprvalue>true</rtexprvalue><!-- 设置是否支持EL表达式 -->
  	</attribute>
  </tag>
  <!-- 函数 -->
  <function>
  	   <name>getParmMapValue</name>
  	   <function-class>com.test.frame.tags.Functions</function-class>
   	   <function-signature> java.lang.String getParmMapValue(java.lang.String)</function-signature>
  </function>
</taglib>
package com.test.frame.tags;
/**
 * 自定义标签
 */
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;
public class ListValueTag extends SimpleTagSupport {
	private String type;
	private String value;
	
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	@SuppressWarnings("unchecked")
	public void doTag() throws JspException, IOException{
		String name = "";
		if(type != null && value != null)
		{
		    //这里就是你需要通过你传递的参数得到你想要值
		    name = type + " is " + value;
		}
		
		JspWriter out = this.getJspContext().getOut();
		out.print(name);
	}
}
package com.test.frame.tags;
public class Functions {		
	/**
	 * 返回参数映射值
	 * @param paramName 参数名
	 * @param parms 参数
	 * @return
	 */
	public static String getParmMapValue(String parmName){
		String result = "";
		if(parmName != null){
		    result = parmName + " is Over";
		}
		return result;
		
	}		
	
}
<%@ taglib uri="/WEB-INF/mln.tld" prefix="test"%>
测试:<test:listValueName type="MayTag" value="Over"/>
测试:<input type="text" id="test" name="test" value="${mln:getParmMapValue('MayFunction')}" >