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 = <COUNTER>;
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 <applet> tag to embed this applet
* at the location where you want to display the count.
*/
//---------------------------------------------------------------
import java.awt.*;
import java.applet.*;
import java.net.*;
import java.io.*;
public class VisitCount extends java.applet.Applet
{
String visitCount; // String to store visitor count
//Class initialization method
public void init()
{
try
{
// Open the URL that counts visitors to this site
// *** Edit URL before using at your site ***
URL url = new URL(
"http://www.sina.com.cn/exec-bin/count.pl?update=1");
// Open a data stream and read a single line
try
{
DataInputStream in = new
DataInputStream(url.openStream());
visitCount = in.readLine();
}
catch(IOException e)
{
}
}
catch(MalformedURLException e)
{
}
}
// Method that paints the output
public void paint(java.awt.Graphics gc)
{
// Display the visitor count that was read from the URL
// Use whatever font style and color you want
// I used Helvetica for a message and a Courier font
// for the visitor count
Font helv = new Font("Helvetica", Font.BOLD, 16);
Font courier = new Font("Courier", Font.BOLD, 24);
gc.setFont(helv);
FontMetrics fm = gc.getFontMetrics();
String message = "Visitor number: ";
int xstart = 0;
int ystart = fm.getHeight();
gc.drawString(message, xstart, ystart);
// Advance horizontally by amount needed to display message
xstart += fm.stringWidth(message);
// Change font to Courier and display the count
gc.setFont(courier);
gc.setColor(Color.red);
gc.drawString(visitCount, xstart, ystart);
}
}
-----------------------------------------------------------------
HTML文件中调用方法.
<applet code=VisitCount width=200 height=26 align=middle></applet>
--------------------------------------------------------------
#!/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 = <COUNTER>;
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 <applet> tag to embed this applet
* at the location where you want to display the count.
*/
//---------------------------------------------------------------
import java.awt.*;
import java.applet.*;
import java.net.*;
import java.io.*;
public class VisitCount extends java.applet.Applet
{
String visitCount; // String to store visitor count
//Class initialization method
public void init()
{
try
{
// Open the URL that counts visitors to this site
// *** Edit URL before using at your site ***
URL url = new URL(
"http://www.sina.com.cn/exec-bin/count.pl?update=1");
// Open a data stream and read a single line
try
{
DataInputStream in = new
DataInputStream(url.openStream());
visitCount = in.readLine();
}
catch(IOException e)
{
}
}
catch(MalformedURLException e)
{
}
}
// Method that paints the output
public void paint(java.awt.Graphics gc)
{
// Display the visitor count that was read from the URL
// Use whatever font style and color you want
// I used Helvetica for a message and a Courier font
// for the visitor count
Font helv = new Font("Helvetica", Font.BOLD, 16);
Font courier = new Font("Courier", Font.BOLD, 24);
gc.setFont(helv);
FontMetrics fm = gc.getFontMetrics();
String message = "Visitor number: ";
int xstart = 0;
int ystart = fm.getHeight();
gc.drawString(message, xstart, ystart);
// Advance horizontally by amount needed to display message
xstart += fm.stringWidth(message);
// Change font to Courier and display the count
gc.setFont(courier);
gc.setColor(Color.red);
gc.drawString(visitCount, xstart, ystart);
}
}
-----------------------------------------------------------------
HTML文件中调用方法.
<applet code=VisitCount width=200 height=26 align=middle></applet>
if (my_File.exists())
{
try{
FileReader r=new FileReader(my_File);
char c[]=new char[9999];
r.read(c);
String t=new String(c);//可用语页面输出
Integer i=new Integer(t);
int p=i.intValue()+1;//记数加1
FileWriter w=new FileWriter(my_File);
w.write((String)p);
w.flush();
}
catch(Exception e)
{
System.out.print(e);
}
}
这只是代码片段,不过我想你应该够了!
谢谢你啊,可惜我已经给过分了。下次一定给你!
只需要人民币20元,你就可以获得本灌水机的程序和Visual C++源代码,并获得永久性技术支持。还等什么?灌水等着你!就在今夜!元宵佳节!(可怜我信誉)