1. Demo traditional Custom Label (jsp2.0 previous)
use a custom label to control whether the page content (label body) is output, using the return value of doStartTag () to control
return this. Skip_body; Ignore label body
return this. Eval_body_include; Execution label Body
control the output of the entire JSP using the return value of Doendtag ()
return this. Skip_page; The remaining JSP code after skipping the page label
return this. Eval_page; Continue to execute the remaining JSP code
The Custom Label implementation content (tag body) Cyclic output is implemented using the Doafterbody () and return value Eval_body_again,skip_body defined in the tag sub-interface iteration
First overwrite the doStartTag () method and return Eval_body_include
Overlay Doafterbody ()
public int doafterbody () throws jspexception {times++; int result = this.
Eval_body_again; if (times>4) {result = this.
Skip_body;
return result;
Custom Label modification content (tag body) eval_body_buffered;
Label processing class: Inherit Bodytagsupport overlay doStartTag (), and return eval_body_buffered;
Overwrite Doendtag () public int doendtag () throws jspexception {bodycontent BC = this.getbodycontent ();
String C = bc.getstring ();
c = C.touppercase ();
JspWriter out = This.pageContext.getOut ();
try {out.write (c);
catch (IOException e) {throw new RuntimeException (e); return this.
Eval_page;
2, requirements: To implement a custom label function: To determine a YYYY-MM-DD format date modified to the following format output year: YYYY month: MM Day: DD Analysis: Custom Label processing class (Demo5.java) package com.csdn.web.tag;
Import java.io.IOException;
Import javax.servlet.jsp.JspException;
Import Javax.servlet.jsp.JspWriter;
Import javax.servlet.jsp.tagext.BodyContent;
Import Javax.servlet.jsp.tagext.BodyTagSupport;
Import Javax.servlet.jsp.tagext.Tag; public class Demo5 extends Bodytagsupport {@Override public int doendtag () throws Jspexception {bodycontent BC = this.getbodycontent ();
String B = bc.getstring ();
string[] data = B.split ("-");
JspWriter out = This.pageContext.getOut ();
try {out.println ("Year:" +data[0]+ "<br>");
Out.println ("Month:" +data[1]+ "<br>");
Out.println ("Day:" +data[2]+ "<br>");
catch (IOException e) {e.printstacktrace ();
return tag.eval_page; The display time to convert 6.jsp <%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%> <%@ taglib uri= "/csdn" prefix= "Csdn"%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >