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 XML Version = "1.0" encoding = "ISO-8859-1"> tag> taglib> (3) Create a JSP file index.jsp <% @ Taglib URI = "/ taguri" prefix = "freo"%> fomto: bookview> body> html> (4) Deployment Tomcat Web.xml XML Version = "1.0" Encoding = "ISO-8859-1">
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 .--> web-app> 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. loops h1>
<% = index.intValue ()%> p>