JSP counter code

Source: Internet
Author: User

<! --
JSP-hitcounter counts sessions.
Copyright (c) 2000 Jesper Schmitz mouridsen.
Visit www. webappcabaret/jsm2/webapps. jsp? Find = jsphcs for more info.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the license, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a participant purpose. see the GNU General Public License at http://www.opensource.org/licenses/gpl-license.html For more details
-->

<%

Bufferedreader INF = new bufferedreader (New filereader ("/path/to/counter.txt "));
Int TMP = integer. parseint (INF. Readline ());
Int I = 0;

Try {

I = integer. parseint (request. getsession (). getvalue ("tal"). tostring ());
} Catch (nullpointerexception t) {I = 0 ;}

If (I = 0 ){
TMP ++;

Printwriter outf = new printwriter (New bufferedwriter (New filewriter ("/path/to/counter.txt ")));
Outf. println (TMP );
Outf. Close ();
INF. Close ();
Request. getsession (). putvalue ("tal", "1 ");
}

Bufferedreader inf2 = new bufferedreader (New filereader ("/path/to/counter.txt "));
%>
<%
String zeroes = "";
String hits = inf2.readline ();
Inf2.close ();
For (int t = 0; t <8-hits.length (); t ++ ){
Zeroes = zeroes + "0 ";}
Out. println (zeroes + hits );
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.