jsp:tld标签

z注意每个uri地址要保持统一

 

1.创建MytagPrinta.java文件

package cn.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;

public class MytagPrinta extends TagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	protected String value = null;
	protected String type = "0";
	
	

	
	public String getValue() {
		return value;
	}


	public void setValue(String value) {
		this.value = value;
	}


	public String getType() {
		return type;
	}


	public void setType(String type) {
		this.type = type;
	}



	@Override
	public int doStartTag() throws JspException {
		// TODO Auto-generated method stub

		try {
			if(type.equals("0"))
			{
				pageContext.getOut().println("hello:" + value);
			}else{
				pageContext.getOut().print("hell:"+value+"
"); } } catch (IOException e) { // TODO Auto-generated catch block throw new JspTagException( e.getMessage() ); } return SKIP_PAGE; } @Override public int doEndTag() throws JspException { // TODO Auto-generated method stub return EVAL_PAGE; } }

  

2.配置web-info下的web.xml文件


      
		http://www.tag.com/mytag  
		/WEB-INF/mytlds/mytag.tld  
	  
	 
 

  3.web-info下的mytlds文件夹下创建 mytag.tld



mytag 带type和value属性的打印
mytag 标签库
1.0
mytag
http://www.tag.com/mytag


	打印value和type
	printa
	cn.tag.MytagPrinta
	empty
	
		type
		false
		true
	
	
		value
		true
		true
	
	



  

4.新建tag.jsp文件。调用

<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="mytag" uri="http://www.tag.com/mytag" %>



带属性标签实例



调用带属性的print标签

打印后换行: 打印后不换行:

  

 

你可能感兴趣的:(jsp:tld标签)