JSP 标签 tag

来源:互联网 发布:app推广链接php源码 编辑:程序博客网 时间:2024/05/22 06:19

class+tld+jsp

 

Hello.jsp

package com.tao.tag;import java.io.IOException;import javax.servlet.jsp.JspException;import javax.servlet.jsp.JspWriter;import javax.servlet.jsp.PageContext;import javax.servlet.jsp.tagext.Tag;public class Hello implements Tag {private PageContext pageContext;private Tag tag;public int doEndTag() throws JspException {// TODO Auto-generated method stubString str="Hello Jsp Tag!";JspWriter out=pageContext.getOut();try {out.println(str);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}return this.EVAL_PAGE;}public int doStartTag() throws JspException {// TODO Auto-generated method stubreturn this.SKIP_PAGE;}public Tag getParent() {// TODO Auto-generated method stubreturn tag;}public void release() {// TODO Auto-generated method stub}public void setPageContext(PageContext pc) {// TODO Auto-generated method stubthis.pageContext=pc;}public void setParent(Tag t) {// TODO Auto-generated method stubthis.tag=t;}}

mytag.tld

<?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>short-name</short-name>  <uri>myFirstTag</uri>  <tag>    <name>hello</name>    <tag-class>com.tao.tag.Hello</tag-class>    <body-content>empty</body-content>  </tag></taglib>


MyTag01.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%><%@ taglib uri="myFirstTag" prefix="c"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>My JSP 'MyTag01.jsp' starting page</title></head><body><br>This is my JSP page.<br><c:hello/></body></html>

效果图:

 

0 0
原创粉丝点击