how to restrict a jsp hit counter?

Posted by user261002 on Stack Overflow See other posts from Stack Overflow or by user261002
Published on 2010-04-18T14:48:24Z Indexed on 2010/04/18 14:53 UTC
Read the original article Hit count: 492

Filed under:
|
|

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;
}

}

© Stack Overflow or respective owner

Related posts about jsp

Related posts about hit