Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

7.9 Example: Simple Prime Tag Using Tag Files

Let's rewrite the simple prime custom tag example using tag files. Listing 7.17 shows simplePrime2.tag. It consists of just one line invoking the static method nextPrime of the Primes class. The Primes.java file is shown in Listing 7.4. We place the simplePrime2.tag file into the WEB-INF/tags directory. Listing 7.18 shows simple-primes-2.jsp, which uses our JSP-based custom tag. Note that the taglib directive no longer has a uri attribute, but uses a tagdir attribute instead. This attribute tells the container which directory contains the tag files. Figure 7-6 shows the result of simple-primes-2.jsp.

Listing 7.17. simplePrime2.tag

<%= coreservlets.Primes.nextPrime
      (coreservlets.Primes.random(50)) %>

Listing 7.18. simple-primes-2.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Some 50-Digit Primes</TITLE>
<LINK REL=STYLESHEET
      HREF="JSP-Styles.css"
      TYPE="text/css">
</HEAD>
<BODY>
<H1>Some 50-Digit Primes</H1>
<%@ taglib tagdir="/WEB-INF/tags" prefix="csajsp" %>
<UL>
  <LI><csajsp:simplePrime2 />
  <LI><csajsp:simplePrime2 />
  <LI><csajsp:simplePrime2 />
  <LI><csajsp:simplePrime2 />
</UL>
</BODY></HTML>
Figure 7-6

Figure 7-6 Result of simple-primes-2.jsp.

  • + Share This
  • 🔖 Save To Your Account