Show animated numbers on the page
Count. Java
Package COM. lpy; import Java. io. *; public class count {/** write count to the filename file */public static void writefile (string filename, Long Count) {try {printwriter out = new printwriter (New filewriter (filename); out. println (count); out. close ();} catch (ioexception e) {e. printstacktrace () ;}}/** read count from the filename file and return */public static long readfile (string filename) {file F = new file (filename ); long Count = 0; if (! F. exists () {// if the file does not exist, call writefile and merge it into 0 writefile (filename, 0);} Try {bufferedreader in = new bufferedreader (New filereader (f )); count = long. parselong (in. readline ();} catch (filenotfoundexception e) {e. printstacktrace ();} catch (ioexception e) {e. printstacktrace ();} catch (numberformatexception e) {e. printstacktrace ();} return count;}/** convert count into a string and read it into the tag to replace it with a file name of 0, 1, 2 ...... */Public static string Tranform (Long Count) {string strcount = "" + count; string newstring = ""; for (INT I = 0; I <strcount. length (); I ++) {newstring + = " ";} return newstring ;}}
Index. jsp
<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" UTF-8 "%> <% @ page import =" com. lpy. count "%> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <HTML>
,,,,,,,,,