<?xml version= "1.0" encoding= "UTF-8" ?> <taglib xmlns= "http://java.sun.com/ Xml/ns/j2ee " xmlns:xsi=" Http://www.w3.org/2001/XMLSchema-instance " xsi:schemalocation= "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ Web-jsptaglibrary_2_0.xsd " version=" 2.0 "> <!-- Description used to add a description of the Taglib (tag library) --> <description> The custom tag library developed by Aloof Wolf </ description> <!--taglib (Tag Library) version number --> < tlib-version>1.0</tlib-version> <short-name>gacltaglibrary</ short-name> <!-- Set a Uri,uri to/from the custom tag library, and/or the following, as/gacl , in the JSP page when referencing the tag library , you need to find the tag library by Uri in the JSP page.Sample Introduction Tag library: <% @taglib uri= "/gacl" prefix= "GaCl"%> --> <uri>/gacl</uri> <!--a taglib (tag library) contains multiple custom labels, each of which uses a tag tag to describe --> <!-- A tag tag corresponding to a custom label --> <tag> <description> The purpose of this tag is to output the IP address of the client </ description> <!-- label Processor class with a label name, when using a tag in a JSP page, the tag name is used to locate the tag processor class to be called can find the corresponding Me.gacl.web.tag.ViewIPTag class by Viewip --> <name> viewip</name> <!-- Tag corresponding processor class--> <tag-class>cn.springmvc.controller.viewiptag</tag-class> <body-content>jsp</body-content><!-- empty or --> <attribute><name>userName</name><required>true</required><rtexprvalue>true</rtexprvalue></attribute> </tag> </taglib><xdp:viewip username= "John1231" > add </xdp:viewip> package cn.springmvc.controller;import java.io.ioexception; import javax.servlet.http.HttpServletRequest;import javax.servlet.jsp.JspException;import Javax.servlet.jsp.jspwriter;import javax.servlet.jsp.pagecontext;import javax.servlet.jsp.tagext.tag ;p ublic class viewiptag implements tag { // Receive PageContext objects passed in private PageContext pageContext; private string username; @Override public int doendtag () throws JspException { System.out.println ("Call Doendtag () method"); return 0; } @Override public int dostarttag () throws JspException { system.out.println ("Call doStartTag () method"); system.out.println (UserName); httpservletrequest request = (HttpServletRequest) pagecontext.getrequest (); jspwriter out = pagecontext.getout (); &NBSP;&NBSP;&NBSP;&NBSP;STRING&NBSP;IP&NBSP;=&NBSP;REQUEST.GETREMOTEADDR (); try { // Here the output will throw IOException exception out.write (IP); out.write ("
Java Custom Label passing value