荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: icefire (35.5), 信区: Java
标  题: 访问计数器---使用JAVA Applet和CGI
发信站: 深大荔园晨风站 (Thu Apr  9 11:32:27 1998), 转信



发信人: dong (春天来了...), 信区: Java
标 题: 访问计数器---使用JAVA Applet和CGI
发信站: BBS 水木清华站 (Fri Apr 11 13:58:40 1997)

这里有个JAVA和CGI程序结合的访问计数器的例子.
其实单纯做访问计数器,只有CGI就够了.
但希望统计用户访问该主页的时间时,只用CGI好象就不行了. (本例没有这个功能. :PPP)

count.pl
--------------------------------------------------------------
#!/usr/local/bin/perl
# Increments a visit count stored in the file named
# "counter" and send the count as a plain text document.

# Print a minimal MIME header
print "Content-type: text/plain\n\n";

$counterfile = "counter";

# Open the counter file and get current count
open(COUNTER, "$counterfile");

# Lock the file to guard against another process updating the
# file as this script uses it
$lock_exclusive = 2;
$unlock = 8;
flock(COUNTER, $lock_exclusive);

# Read and increment the count
$line = ;
close(COUNTER);

chop($line);
$count = $line;
$count++;

# Save the new count in the file
open(COUNTER, ">$counterfile");
print COUNTER ("$count\n");
close(COUNTER);

# Remember to unlock the file
flock(COUNTER, $unlock);

# Send count to caller
print "$count\n";
------------------------------------------------------------
VisitCount.java

----------------------------------------------------------
//---------------------------------------------------------------
// File: VisitCount.java
// Accesses a CGI program to update visit count and display
// the current count.
// Compile with: javac VisitCount.java
/*
* The VisitCount class is a Java applet that accesses a CGI
* program at the host URL and retrieves the visitor count (the
* CGI program also updates the count). Then it displays the
* current count. Use an
--
来去如风

※ 来源:.深大荔园晨风站 bbs.szu.edu.cn.[FROM: 202.192.140.5]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店