Realize loop function with label --- Tag development three (Inber original)

xiaoxiao2021-03-06  101

Realize loop function with label --- Tag development three (Inber original)

Main practice knowledge points: page and script variable keyword: page and script variable, label

Step 1: Label handler: fortag.java

Package net.inber.jsptaglibs.Ipect;

Import javax.servlet.jsp. *; import javax.servlet.jsp.tagext. *;

/ ** * Given a Range of Values, this tag itreates over each value and makes it * available to the page. * * @Author Inber gong * / public class fortag outs tagsupport {

/ ** The starting index (defaults to zero) * / private int from = 0;

/ ** The finishing index * / private int

/ ** the current index * / private int index;

/ ** * Called when the starting tag is encountered. * / Public int dostarttag () throws jspexception {// setup the counter variable index = from

IF (Index

// and incrude the body;} else {// there no elements so skip the body return skip_body;}}

/ ** * called after the body has been incruded. * / Public int dressbody () THROWS JSPEXCEPTION {// increment the counter inex

IF (index

// and instruct the jsp engine to re-evaryuate the body of this tag return eval_body_again;} else {// there is are no more elements so skip the body return skip_body;}}

/ ** * setter for the "from" attribute. * * @Param I an integer value * / public void setfrom (int i) {this.from = i;}

/ ** * setter for the "to" attribute. * * @Param I an integer value * / public void setto (int i) {this.to = i;}} (2) Configure the label library descriptor (TLD) file ConfigTLD.TLD A Tag Library Exercising SimpleTag Handlers. 1.0 Examples / Demotag A Simple Tab Library For the example

BookView Net.inber.jsptaglibs.Itemization.fortag JSP index java.lang.integer true jsp

from True TRUE

to true TRUE

(3) Create a JSP file index.jsp <% @ Taglib URI = "/ taguri" prefix = "freo"%>

loops


<% = index.intValue ()%>

(4) Deployment Tomcat Web.xml

Licensed Under The Apache License, Version 2.0 (The "license"); You May Not Use this file exceptin compliance with the license. You may Obtain a Copy of the license At

http://www.apache.org/license/license-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations Under the license .-->

Welcome to Tomcat Welcome to Tomcat

/ taguri /web-inf/tlds/configTLD.TLD

Ok, you will do it, the source file download address: http://inber.51.net/9cbs_blog/soft/fortag.rag If you have a problem, please contact me.

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

New Post(0)