JSP custom tag (3)

Source: Internet
Author: User
8. simpletagsupport class

After jsp2.0, simpletagsupport can be used for development to simplify tag development;

1. Develop general labels

Note:

(1) The simpletagsupport class must be inherited;

(2) implement public voidDotag() Throws jspexception, ioexception;

(3) super.Getjspcontext().Getout().Write("..."); Output;

(4) In simpletagsupport, the content of <body-content> in TLD cannot be JSP. If the label body is not empty, it can only beScriptless;

Code:

Simpletagsupportdemo. Java

package org.tagext;import javax.servlet.jsp.tagext.*;import javax.servlet.jsp.*;import java.io.*;public class SimpleTagSupportDemo extends SimpleTagSupport{private String name;public String getName(){return name;}public void setName(String name){this.name = name;}public void doTag()throws JspException,IOException{super.getJspContext().getOut().write("

2. The development iteration tag is passed through Super. getjspbody (). Invoke (null); the label body content can be executed; simpletagsuppdemo demo. Java
package org.tagext;import javax.servlet.jsp.tagext.*;import javax.servlet.jsp.*;import java.io.*;import java.util.*;public class SimpleTagSupportDemo extends SimpleTagSupport{private String name;private String id;public String getName(){return name;}public void setName(String name){this.name = name;}public String getId(){return id;}public void setId(String id){this.id = id;}public void doTag()throws JspException,IOException{Object value = super.getJspContext().getAttribute(name,PageContext.PAGE_SCOPE);Iterator<String> iter = ((List<String>)value).iterator();while(iter.hasNext()){super.getJspContext().setAttribute(id,iter.next());super.getJspBody().invoke(null);}}}

In general, simpletagsupport is much simpler than the previous tagsupport and bodytagsupport, and no return value is required.

1. Identify whether there is a TAG body

<Xiazdong: Hello name = "">

</Xiazdong: Hello>

It belongs to a TAG body, but the TAG body is empty;

<Xiazdong: Hello name = ""/> the label body is empty;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.