jsp自定义标签库

package com.mycode.action;

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

public class MyTag extends TagSupport {
	private static final long serialVersionUID = 1L;
	public MyTag() {
		super();
	}
	@Override
	public int doEndTag() throws JspException {
		try {
			pageContext.getOut().print("test  haihao");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SKIP_BODY;
	}
	@Override
	public void release() {
		super.release();
	}
}


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 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-app_2_4.xsd">

	<taglib>
		<taglib-uri>/mytaglib</taglib-uri>
		<taglib-location>/WEB-INF/mytaglib.tld</taglib-location>
	</taglib>

	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
</web-app>


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE taglib   
 	PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" 	
 	"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
	<tlib-version>1.0</tlib-version>
	<jsp-version>1.2</jsp-version>
	<short-name>mytaglib</short-name>
	<uri>/mytaglib</uri>

	<tag>
		<name>hello</name>
		<tag-class>com.mycode.action.MyTag</tag-class>
		<body-content>empty</body-content>
	</tag>
</taglib> 	


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/mytaglib" prefix="mm" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <body>
  <mm:hello/>
  </body>
</html>



你可能感兴趣的:(java,html,jsp)