当前位置: 技术问答>java相关
使用jsp做一个网站计数器,都有什么方法?
来源: 互联网 发布时间:2015-05-01
本文导语: 使用jsp做一个网站计数器,都有什么方法? 不用数据库怎么实现 | counter.java package UsefulClasses; import java.sql.*; public class Counter { private int count; private Database Mechanism=new Database(); public Counte...
使用jsp做一个网站计数器,都有什么方法?
不用数据库怎么实现
不用数据库怎么实现
|
counter.java
package UsefulClasses;
import java.sql.*;
public class Counter
{
private int count;
private Database Mechanism=new Database();
public Counter()
{
ResultSet rs=Mechanism.executeQuery("select Counter from Counter");
try
{
while (rs.next())
{
count=rs.getInt("Counter");
}
}
catch(SQLException ex)
{
System.err.println("SQL select error:" + ex.getMessage());
}
finally
{
Mechanism.closeStmt();
Mechanism.closeConn();
}
}
synchronized public void Increase()
{
count++;
}
synchronized public String[] getCountImage()
{
char[] chars=String.valueOf(count).toCharArray();
int numChars=chars.length;
String[] images=new String[numChars];
for (int LoopNum=numChars-1;LoopNum>-1;LoopNum--)
{
images[LoopNum]=String.valueOf(chars[LoopNum])+".gif";
}
return images;
}
synchronized public void UpdateCounter()
{
Mechanism.executeUpdate("update Counter set Counter="+count);
}
}
counter.jsp
您是第
位访客
package UsefulClasses;
import java.sql.*;
public class Counter
{
private int count;
private Database Mechanism=new Database();
public Counter()
{
ResultSet rs=Mechanism.executeQuery("select Counter from Counter");
try
{
while (rs.next())
{
count=rs.getInt("Counter");
}
}
catch(SQLException ex)
{
System.err.println("SQL select error:" + ex.getMessage());
}
finally
{
Mechanism.closeStmt();
Mechanism.closeConn();
}
}
synchronized public void Increase()
{
count++;
}
synchronized public String[] getCountImage()
{
char[] chars=String.valueOf(count).toCharArray();
int numChars=chars.length;
String[] images=new String[numChars];
for (int LoopNum=numChars-1;LoopNum>-1;LoopNum--)
{
images[LoopNum]=String.valueOf(chars[LoopNum])+".gif";
}
return images;
}
synchronized public void UpdateCounter()
{
Mechanism.executeUpdate("update Counter set Counter="+count);
}
}
counter.jsp
您是第
位访客