1.对于不同的id,进行记录次数。当次数超过一定次数,作出相应的处理。
例如:当超过5次(含有)作出处理
counter为常量 可以定义成员属性 private int counter ;
errorTime错误的次数,private int errorTime = 1.
counter = Integer.parseInt(context.getProperty("validate.pin.counter"));// 5 times
if(session.getAttribute(Constant.VALIDATE_PIN) != null ){
errorTime = Integer.parseInt(session.getAttribute(Constant.VALIDATE_PIN).toString());
info(method,"get error time form session --------" + errorTime);
if(errorTime >= counter){
info(method,"user enter pinNo " + pinNo + "more than 5 times ");
isShow = "Show";
return INPUT;
}
}
errorTime++;
session.setAttribute(Constant.VALIDATE_PIN, errorTime);
2.对于相同的id,进行记录次数。当次数超过一定次数,作出相应的处理。
例如:当超过5次(含有)作出处理
private int counter;
Map<String, Integer> countMap = (Map<String, Integer>) session
.getAttribute(Constant.SELF_SERVICE_ACTION.FORGOTPASS_COUNTMAP);
if (countMap == null) {
countMap = new HashMap<String, Integer>();
}
Iterator iterator = countMap.entrySet().iterator();
boolean isExist = false;
counter = Integer.parseInt(context.getProperty("forgot.password.Counter"));// 5 times
while (iterator.hasNext()) {
Map.Entry<String, Integer> entry = (Map.Entry<String, Integer>) iterator
.next();
String keyCustId = (String) entry.getKey();
Integer valCount = (Integer) entry.getValue();
if (keyCustId.equals(ssoUser.getCustId())) {
valCount++;
if (valCount.intValue() >= counter) {
info(method,"custId or emailAddress invalid more than 5 times lead to forgotssoId page");
try {
questionList = selfServiceManager.getQuestionList();
return "forgotssoId";
} catch (SelfServiceManagerException e) {
error(method, "get question exception by manager", e);
ctx.put(errorMessage, getText("error.forgot.password.exception.questionlist"));
return ERROR;
}
}
countMap.put(keyCustId, valCount);
isExist = true;//不在5次的范围内
break;
}
}
if (!isExist) {
debug(method, "First time a user submitted with custid is"
+ ssoUser.getCustId());
countMap.put(ssoUser.getCustId(),
Constant.SELF_SERVICE_ACTION.FORGOTPASS_INIT_COUNTER);
}
session.setAttribute(Constant.SELF_SERVICE_ACTION.FORGOTPASS_COUNTMAP, countMap);//放到session中
Author:lyuan
Date : 3/5/2010, 3:57 PM