Defining a Simple Tag Handler 
Class: Example
package cwp.tags;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import java.math.*;
import cwp.*;
public class SimplePrimeTag
extends TagSupport
{
protected int len = 50;
public int 
doStartTag
() {
try {
JspWriter out = pageContext.getOut();
BigInteger prime = 
Primes.nextPrime(Primes.random(len));
out.print(prime);
} catch(IOException ioe) {
System.out.println("Error generating prime: " + ioe);
}
return(SKIP_BODY);
}}
81
JSP
www.corewebprogramming.com
Defining a Simple Tag Library 
Descriptor
Start with XML header and DOCTYPE
Top level element is
taglib
Each tag defined by tag element containing:
name, whose body defines the base tag name. 
In this case, I use 
simplePrime
tagclass, which gives the fully qualified class name of the 
tag handler. In this case, I use 
cwp.tags.SimplePrimeTag
bodycontent, which gives hints to development 
environments. Optional. 
info, which gives a short description. Here, I use
Outputs a random 50 digit prime.
82
JSP
www.corewebprogramming.com
41




  

Home

About Services Network Support FAQ Order Contact
 

Java Web Hosting

Our partners:Jsp Web Hosting Unlimited Web Hosting Cheapest Web Hosting  Java Web Hosting Web Templates Best Web Templates PHP Mysql Web Hosting Interland Web Hosting Cheap Web Hosting PHP Web Hosting Tomcat Web Hosting Quality Web Hosting Best Web Hosting  Mac Web Hosting 

Lunarwebhost.net  Business web hosting division of Vision Web Hosting Inc. All rights reserved