告诉你一个最简单的:
package com.tag.DateTag;import javax.servlet.jsp.tagext.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.text.*;public class DateTag extends TagSupport
{
    public int doStartTag() throws JspException
    {
        return SKIP_BODY;
    }
    public int doEndTag() throws JspException
    {
        JspWriter writer = pageContext.getOut();
        Locale locale = null;
        DateFormat format = null;
        HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
        locale = request.getLocale();
        try
        {
            format = SimpleDateFormat.getDateInstance(SimpleDateFormat.FULL, locale);
            String strDate = format.format(new java.util.Date());
            writer.print(strDate);
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return EVAL_PAGE;
    }
}
//-----------tld文件种的配置-----------
<tag>
       <name>dateTag</name>
       <tagclass>com.tag.DateTag</tagclass>
       <bodycontent>JSP</bodycontent>
       <info>Get web server system now time</info>
  </tag>
//--------JSP---------
<%@ taglib uri="/WEB-INF/taglib.tld" prefix="free" %>
<free:dateTag/>//祝你好运

解决方案 »

  1.   

    我也来帖一个
    java文件HelloTag,编译的 class文件放到web-inf的classes文件夹下:
    -----------------------------------------
    import java.io.IOException;
    import javax.servlet.jsp.tagext.*;public class HelloTag extends TagSupport { // The "person" to say hello to
    private String name;
     
    // Accept the attribute data
    public void setName(String name) {
      this.name = name;
    } public int doEndTag() {
      try {
      StringBuffer message = new StringBuffer("Hello, ");
      message.append(name)
     .append("!");
      pageContext.getOut().println(message.toString());
    } catch (IOException ignored) { }
    return EVAL_PAGE;
    }
    }tld 文件:放在web-inf文件夹下
    -------------------------------------------------------------
    <?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>zty</shortname>  <uri>http://localhost:8080/web-inf/zty</uri>  <tag>
        <name>hello</name>
        <tagclass>HelloTag</tagclass> 
        <bodycontent>JSP</bodycontent> 
        <attribute>
          <name>name</name>
          <required>true</required>
          <rtexprvalue>false</rtexprvalue>
        </attribute>
      </tag>
    </taglib>JSP中
    ------------------------------------------------
    <%@ page language="java" pageEncoding="GB2312"%>
    <%@ taglib uri="/WEB-INF/zty.tld" prefix="zty" %>
    <html>
    <head>
    <title>HELLO</title>
    </head>
    <body bgcolor="#FFFFFF">
    <zty:hello name="Reader" />
    </body>
    </html>