Category: FromSitesTree.com

PrimeNumbers.java Servlet that processes a request to generate n prime numbers, each with at least m digits. If these results are not complete, it sends a Refresh header instructing the browser to ask for new results a little while later. Uses the Primes #Programming Code Examples #Java/J2EE/J2ME #Servlet

PrimeNumbers.java Servlet that processes a request to generate n prime numbers, each with at least m digits. If these results are not complete, it sends a Refresh header instructing the browser to ask for new results a little while later. Uses the Primes, PrimeList, and ServletUtilities classes. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; …

Continue reading

SetCookies.java Servlet that sets a few persistent and session cookies. Uses the ServletUtilities class to simplify the DOCTYPE and HEAD output. #Programming Code Examples #Java/J2EE/J2ME #Servlet

SetCookies.java Servlet that sets a few persistent and session cookies. Uses the ServletUtilities class to simplify the DOCTYPE and HEAD output. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** Sets six cookies: three that apply only to the current * session (regardless of how long that session lasts) * and three that persist for …

Continue reading

ShowCookies.java Servlet that displays all cookies that arrived in current request. Uses the ServletUtilities class. #Programming Code Examples #Java/J2EE/J2ME #Servlet

ShowCookies.java Servlet that displays all cookies that arrived in current request. Uses the ServletUtilities class. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** Sets six cookies: three that apply only to the current * session (regardless of how long that session lasts) * and three that persist for an hour (regardless of * whether …

Continue reading

LongLivedCookie.java Subclass of Cookie that automatically sets the max age to one year. #Programming Code Examples #Java/J2EE/J2ME #Servlet

LongLivedCookie.java Subclass of Cookie that automatically sets the max age to one year. package cwp; import javax.servlet.http.*; /** Cookie that persists 1 year. Default Cookie doesn’t * persist past current session. * * Taken from Core Web Programming Java 2 Edition * from Prentice Hall and Sun Microsystems Press, * . * May be freely …

Continue reading

ShowSession.java Servlet that uses session tracking to determine if the client is a repeat visitor. Uses the ServletUtilities class to simplify the DOCTYPE and HEAD output. #Programming Code Examples #Java/J2EE/J2ME #Servlet

ShowSession.java Servlet that uses session tracking to determine if the client is a repeat visitor. Uses the ServletUtilities class to simplify the DOCTYPE and HEAD output. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import java.util.*; /** Simple example of session tracking. * * Taken from Core Web Programming Java 2 Edition * …

Continue reading

Accesses instance variables in a Ship object. #Programming Code Examples #Java/J2EE/J2ME #Object Oriented Programming

Test1.java Accesses instance variables in a Ship object. ******************************************************** // Create a class with five instance variables (fields): // x, y, speed, direction, and name. Note that Ship1 is // not declared "public", so it can be in the same file as // Test1. A Java file can only contain one "public" class // definition. …

Continue reading

Demonstrates overloading methods in class Ship4 #Programming Code Examples #Java/J2EE/J2ME #Object Oriented Programming

********************* class Ship4 { public double x=0.0, y=0.0, speed=1.0, direction=0.0; public String name; // This constructor takes the parameters explicitly. public Ship4(double x, double y, double speed, double direction, String name) { this.x = x; this.y = y; this.speed = speed; this.direction = direction; this.name = name; } // This constructor requires a name but …

Continue reading

ServletUtilities.java Utility class that, among other things, contains the static filter method that replaces special HTML characters with their HTML character entities. #Programming Code Examples #Java/J2EE/J2ME #Servlet

ServletUtilities.java Utility class that, among other things, contains the static filter method that replaces special HTML characters with their HTML character entities. package cwp; import javax.servlet.*; import javax.servlet.http.*; /** Some simple time savers. Note that most are static methods. * * Taken from Core Web Programming Java 2 Edition * from Prentice Hall and Sun …

Continue reading

ShowRequestHeaders.java Servlet that shows all request headers sent by browser in current request. #Programming Code Examples #Java/J2EE/J2ME #Servlet

ShowRequestHeaders.java Servlet that shows all request headers sent by browser in current request. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; /** Shows all the request headers sent on this request. * * Taken from Core Web Programming Java 2 Edition * from Prentice Hall and Sun Microsystems Press, * . * May …

Continue reading

EncodedPage.java Servlet that shows the bandwidth benefits of gzipping pages to browsers that can handle gzip. Uses the ServletUtilities class to simplify the DOCTYPE and HEAD output. #Programming Code Examples #Java/J2EE/J2ME #Servlet

EncodedPage.java Servlet that shows the bandwidth benefits of gzipping pages to browsers that can handle gzip. Uses the ServletUtilities class to simplify the DOCTYPE and HEAD output. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.zip.*; /** Example showing benefits of gzipping pages to browsers * that can handle gzip. * * Taken from …

Continue reading