Custom tags tutorial

xiaoxiao2021-04-04  309

IT's Very Simple and Not Full. THE Simple Process IS:

1. Write class: The class usually inherit (extend) tagsupport (or some other). The functions Below Are Useful:

Public int doendtag ()

Throws JSPEXCEPTION

Public int desartTAG ()

Throws JSPEXCEPTION

The Example Is Below:

Public class demotag extends tagsupport {private string name = "oriname";

public int doStartTag () throws JspException {// HttpServletRequest request = (HttpServletRequest) pageContext.getRequest (); JspWriter out = pageContext.getOut (); try {out.println ( "Tags Entered .......... Out.println ("Name IS" Name "..............");} catch (ioException e) {E.PrintStackTrace ();} return skip_body; }

Public string getname () {return name;}

Public void setname (string name) {this.name = name;}}

2. Define TLD (Tag Library Define) File, Below Is One Example, The Header of The File Important:

1.0 1.2 site-utils demotag com.tcs.tags.demotag EMPTY name

ON ABOVE, The is The point deciding means.

3. Use the tag in jsp:

3.1 DECLEAR TAGLIB, LIKE: <% @ Taglib Uri = "/ Web-INF / MyTaglib.tld" prefix = "mytag"%>

3.2 USE:

4. OK :)

转载请注明原文地址:https://www.9cbs.com/read-131891.html

New Post(0)