jsp自定义tag

/**
 * 
 */
package tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 * @author Administrator
 *
 */
public class ConstomTag extends SimpleTagSupport {

	
	public void setTemplate(String value){
		
	}
	public void setCategory(String value){
		
	}
	public void category(String value){
		
	}
	public void template(String value){
		
	}
	public void hello(String value){
		
	}
	
	public void setHello(String hello){
		
	}
	public ConstomTag() {
		super();
	}
	@Override
	public void doTag() throws JspException, IOException {
		
		super.doTag();
		JspWriter out=this.getJspContext().getOut();
		out.write("myConstom jsp tag");
//		System.out.println("invoke");
	}
	@Override
	protected Object clone() throws CloneNotSupportedException {
		
		return super.clone();
	}
}

 

<?xml version="1.0" encoding="UTF-8"?>







<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>template</shortname>
<uri>http://cn.isvi.com</uri>
<tag>
<name>hello</name>
<tagclass>tag.ConstomTag</tagclass>
<bodycontent>empty</bodycontent>
<attribute>
<name>template</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>


</taglib>



  定义函数

 

package jspFunction;

public class ConstomFunction {

	//必须 是静态方法,否则Nullpoint
	public static String doAction(){
		return "my constom function"; 
	}
}

 标记文件

 

package jspFunction;

public class ConstomFunction {

	//必须 是静态方法,否则Nullpoint
	public static String doAction(){
		return "my constom function"; 
	}
}

  index.jsp

 

<%@taglib uri="http://cn.isvi.com" prefix="ct"%>
<%@taglib uri="http://myFunction" prefix="myfn"%>

<!--my constom tag--><ct:hello template="template"></ct:hello>
<!--my Constom function-->   	
 ${myfn:doAction()}

你可能感兴趣的:(jsp,xml,Web,servlet,sun)