how to restrict a jsp hit counter?
- by user261002
I am writing a hot counter in jsp, for my coursework. I have write the code, and there is not error and its working, but the problem is that:
if the user have open the website and try to user different page, when ever that the user get back to the home page the counter still is adding a number , how can I restrict this part??? shall restrict it with session??
this is my code :
The current count for the counter bean is:
<%
counter.saveCount();
int _numberofvisitors=counter.getVisitorsNumber();
out.println(_numberofvisitors);
%
Bean:
package counter;
import java.sql.*;
import java.sql.SQLException;
public class CounterBean implements java.io.Serializable {
int coun = 0;
public CounterBean() {
database.DatabaseManager.getInstance().getDatabaseConnection();
}
public int getCoun() {
return this.coun;
}
public void setCoun(int coun) {
this.coun += coun;
}
public boolean saveCount() {
boolean _save = false;
database.SQLUpdateStatement sqlupdate = new database.SQLUpdateStatement("counter", "hitcounter");
sqlupdate.addColumn("hitcounter", getCoun());
if (sqlupdate.Execute()) {
_save = true;
}
return _save;
}
public int getVisitorsNumber() throws SQLException {
int numberOfVisitors = 0;
if (database.DatabaseManager.getInstance().connectionOK()) {
database.SQLSelectStatement sqlselect = new database.SQLSelectStatement("counter", "hitcounter", "0");
ResultSet _userExist = sqlselect.executeWithNoCondition();
if (_userExist.next()) {
numberOfVisitors = _userExist.getInt("hitcounter");
}
}
return numberOfVisitors;
}
}