Test page index.jsp
1 <%--Use the TAGLIB directive to invoke and name custom tags--%>2 <%@ taglib Prefix="Mytags"Tagdir="/web-inf/tags"%>3 4 <HTML>5 <Head>6 <title>Test Set Indicator sign</title>7 </Head>8 <Body>9 <%--Using custom Tags--%>Ten <Mytags:headFontColor= "#660099"> OneThis is the body of a custom label! Sometimes because the tag attribute is too long, even a piece of text.<BR> AIt's too ugly to put them in the start tag, and it's not conducive<Strong>Write</Strong>。<BR> - at this point, the advantages of the body will be reflected. - </Mytags:head> the </Body> - </HTML>
Custom label file Head.tag
1 <%--here"Tag"directives are equivalent to those in the JSP"page"instruction--%>2 3 <!--encoding settings, not missing, otherwise garbled display -4 <%@ tag Pageencoding="UTF-8" %>5 6 <!--declares the type of label body content (no script is allowed), the default scriptless can be an expression, empty does not allow the body, tagdependent the body as plain text, -7 <%@ Tag Body-content="scriptless" %>8 9 <!--required sets whether a property must be declared, Rtexprvalue sets whether the property value can be an expression -Ten <%@ attribute Name="FontColor"Required="true"Rtexprvalue="true"%> One A <Strong>Here is the test!</Strong><BR> - <em> - <FontColor= "${fontcolor}"> the - <!--get the contents of the tag body - - <Jsp:dobody/> - </Font> + </em>
Test results:
Initial custom tag file tag