Tag: Java

PrimeTag.java Custom tag that outputs a random prime number of a user-specifiable approximate length

PrimeTag.java Custom tag that outputs a random prime number of a user-specifiable approximate length package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; /** Generates an N-digit random prime (default N = 50).  *  Extends SimplePrimeTag, adding a length attribute  *  to set the size of the prime. The doStartTag  *  method of the parent class …

Continue reading

SimplePrimeTag.java Custom tag that outputs a random prime number of a fixed approximate length

SimplePrimeTag.java Custom tag that outputs a random prime number of a fixed approximate length package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; import java.math.*; import cwp.*; /** Generates a prime of approximately 50 digits.  *  (50 is actually the length of the random number  *  generated — the first prime above that number will  *  …

Continue reading

cwp-taglib.tld Tag Library Descriptor file used by the custom tags in this chapter.

cwp-taglib.tld Tag Library Descriptor file used by the custom tags in this chapter. <?xml version=”1.0″ encoding=”ISO-8859-1″ ?> <!DOCTYPE taglib  PUBLIC “-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN”  “http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd”> <!– a tag library descriptor –> <taglib>   <!– after this the default space is         “http://java.sun.com/j2ee/dtds/jsptaglibrary_1_2.dtd”    –>   <tlibversion>1.0</tlibversion>   <jspversion>1.1</jspversion>   <shortname>cwp</shortname>   <!– …

Continue reading

SharedCounts1.jsp, SharedCounts2.jsp, and SharedCounts3.jsp Three pages that all use the AccessCountBean. Results you get depend on which page is hit first and how many total hits the combined pages receive.

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”> <!– Example of sharing beans. Taken from Core Web Programming Java 2 Edition from Prentice Hall and Sun Microsystems Press, . May be freely used or adapted. –> <HTML> <HEAD> <TITLE>Shared Access Counts: Page 1</TITLE> <LINK REL=STYLESHEET       HREF=”JSP-Styles.css”       TYPE=”text/css”> </HEAD> <BODY> <TABLE BORDER=5 ALIGN=”CENTER”>   <TR><TH …

Continue reading

SaleEntry3.jsp Page that uses the SaleEntry bean, using property=”*” to read request parameters and assign them to bean properties

SaleEntry3.jsp Page that uses the SaleEntry bean, using property=”*” to read request parameters and assign them to bean properties <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”> <!– Example of using jsp:setProperty and a general association with the input parameters. See SaleEntry1.jsp and SaleEntry2.jsp for alternatives.     Taken from Core Web Programming Java 2 Edition …

Continue reading

SaleEntry1.jsp Page that uses the SaleEntry bean, using explicit Java code to read request parameters and assign them to bean properties.

SaleEntry1.jsp Page that uses the SaleEntry bean, using explicit Java code to read request parameters and assign them to bean properties.   <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”> <!– Example of using jsp:setProperty with an explicit value supplied to the “value” attribute. See SaleEntry2.jsp and SaleEntry3.jsp for alternatives. Taken from Core Web Programming Java …

Continue reading

StringBean.jsp Page that manipulates the StringBean bean with both jsp:useBean (i.e., XML-style) syntax

StringBean.jsp Page that manipulates the StringBean bean with both jsp:useBean (i.e., XML-style) syntax package cwp; /** Simple bean to illustrate sharing beans through  *  use of the scope attribute of jsp:useBean.  *  <P>  *  Taken from Core Web Programming Java 2 Edition  *  from Prentice Hall and Sun Microsystems Press,  *  .  *  May be …

Continue reading

RepeatTag.java Custom tag that repeats the tag body a specified number of times

RepeatTag.java Custom tag that repeats the tag body a specified number of times package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; /** A tag that repeats the body the specified  *  number of times.  *  <P>  *  Taken from Core Web Programming Java 2 Edition  *  from Prentice Hall and Sun Microsystems Press,  *  . …

Continue reading

An applet that reads arrays of strings packaged inside a QueryCollection and places them in a scrolling TextArea.

import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.net.*; /** Applet reads arrays of strings packaged inside  *  a QueryCollection and places them in a scrolling  *  TextArea. The QueryCollection obtains the strings  *  by means of a serialized object input stream  *  connected to the QueryGenerator servlet.  *    *  Taken from Core Web Programming …

Continue reading

FilterTag.java Custom tag that modifies the tag body

FilterTag.java Custom tag that modifies the tag body package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; import cwp.*; /** A tag that replaces <, >, “, and & with their HTML  *  character entities (<, >, “, and &).  *  After filtering, arbitrary strings can be placed  *  in either the page body or in …

Continue reading