JSP: Créer un tag vide

Author:
       
/// Empty Tag
   


  /java2s
  /WEB-INF/java2s.tld


// create Fichier:java2s.tld in the /WEB-INF/


    

  1.0
  1.2
  Java2s Simple Tags

  
  
    emptyTag
    com.java2s.EmptyTag
    empty
  


//compile the following code into WEB-INFclassescomjava2s
package com.java2s;

import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class EmptyTag extends TagSupport
{
  public int doStartTag() throws JspException
  {
    try 
    {
      pageContext.getOut().print("in EmptyTag.doStartTag()");
    }
    catch (IOException e) 
    {
      System.out.println("Error in EmptyTag.doStartTag()");
      e.printStackTrace();
      throw new JspException(e); // throw the error to the error page (if set)
    } // end of try-catch

    return SKIP_BODY;
  }
}



// start comcat and load the following jsp page in browser


<%@ taglib uri="/java2s" prefix="java2s" %>


  
    A custom tag: empty
  
  
    This page uses a custom tag that has neither attributes nor body content.
    Here is its output:
    

                      

A Voir sur le même Sujet:

  • exemple code java

Leave a Reply

Your email address will not be published. Required fields are marked *