Category: FromSitesTree.com

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

ServletTemplate.java Starting point for servlets. #Programming Code Examples #Java/J2EE/J2ME #Servlet

ServletTemplate.java Starting point for servlets. import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** Servlet template. * * Taken from Core Web Programming Java 2 Edition * from Prentice Hall and Sun Microsystems Press, * . * May be freely used or adapted. */ public class ServletTemplate extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws …

Continue reading

HelloWorld.java Simple servlet that generates plain text. #Programming Code Examples #Java/J2EE/J2ME #Servlet

HelloWorld.java Simple servlet that generates plain text. import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** Very simplistic servlet that generates plain text. * * Taken from Core Web Programming Java 2 Edition * from Prentice Hall and Sun Microsystems Press, * . * May be freely used or adapted. */ public class HelloWorld extends HttpServlet { …

Continue reading

HelloWWW.java Servlet that generates HTML. This and all remaining servlets are in the cwp package and therefore should be installed in the cwp subdirectory. #Programming Code Examples #Java/J2EE/J2ME #Servlet

HelloWWW.java Servlet that generates HTML. This and all remaining servlets are in the cwp package and therefore should be installed in the cwp subdirectory. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** Simple servlet that generates HTML. * * Taken from Core Web Programming Java 2 Edition * from Prentice Hall and Sun Microsystems …

Continue reading

ServletUtilities.java Utility class that simplifies the output of the DOCTYPE and HEAD in servlets, among other things. Used by most remaining servlets in the chapter. #Programming Code Examples #Java/J2EE/J2ME #Servlet

ServletUtilities.java Utility class that simplifies the output of the DOCTYPE and HEAD in servlets, among other things. Used by most remaining servlets in the chapter. 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 …

Continue reading

SimplerHelloWWW.java Servlet that uses ServletUtilities to simplify the generation of the DOCTYPE and HEAD part of the servlet. #Programming Code Examples #Java/J2EE/J2ME #Servlet

SimplerHelloWWW.java Servlet that uses ServletUtilities to simplify the generation of the DOCTYPE and HEAD part of the servlet. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** Simple servlet that generates HTML. This variation of * HelloWWW uses the ServletUtilities utility class * to generate the DOCTYPE, HEAD, and TITLE. * * Taken from Core …

Continue reading

ShowMessage.java Servlet that demonstrates the use of initialization parameters. #Programming Code Examples #Java/J2EE/J2ME #Servlet

ShowMessage.java Servlet that demonstrates the use of initialization parameters. Remember that, to use this servlet, you have to do three things: * Put the modified web.xml file in the WEB-INF directory. * Restart the server. * Use the registered servlet name (i.e., the URL http://host/servlet/ShowMsg), not the raw servlet name (i.e., the URL http://host/servlet/cwp.ShowMessage). package …

Continue reading

ThreeParams.java Servlet that reads and displays three request (form) parameters. Uses the ServletUtilities class. #Programming Code Examples #Java/J2EE/J2ME #Servlet

ThreeParams.java Servlet that reads and displays three request (form) parameters. Uses the ServletUtilities class. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** Simple servlet that reads three parameters from the * form data. * * Taken from Core Web Programming Java 2 Edition * from Prentice Hall and Sun Microsystems Press, * . * …

Continue reading

JavaScript Form Validation: Validate a Form Collecting Credit Card Information #Programming Code Examples #Javascript #JavaScript

function validateCollectPaymentInformationForm() { var method, name, number, expiry, errMsg errMsg = ""; method = document.getElementById(‘paymentMethod’); name = document.getElementById(‘txtCCName’); number = document.getElementById(‘txtCCNumber’); if (method.value == "" || method.value == "0" || method.value == null){ errMsg = "Please select a payment method n"; } if (name.value == "" || name.value == null){ errMsg = errMsg + ‘Please …

Continue reading

GetElementsByName an example: Checkbox #Programming Code Examples #Javascript #JavaScript

<html> <head> <script type="text/javascript"> function getElements() { var x=document.getElementsByName("myInput[]"); alert(x.length); alert(x[0].value); alert(x[1].value); alert(x[2].value); } </script> </head> <body> <input name="myInput[]" type="checkbox" size="20" value=’10’/>10 <input name="myInput[]" type="checkbox" size="20" value=’20’ />20 <input name="myInput[]" type="checkbox" size="20" value=’30’ />30 <br /> <input type="button" onclick="getElements()" value="How many elements named 'myInput'?" /> </body> </html> Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on …

Continue reading