%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%
int interval = 1; // in seconds
String prefix = "ad";
String ext = "html";
if(request.getParameter("reset") != null){
application.setAttribute("lastDate",null);
application.setAttribute("lastIndex","1");
}
java.util.Date lastDate = (java.util.Date)application.getAttribute("lastDate");
if(lastDate == null){
lastDate = new java.util.Date();
application.setAttribute("lastDate",lastDate);
}
String lastIndex = (String)application.getAttribute("lastIndex");
if(lastIndex == null){
lastIndex = "1";
application.setAttribute("lastIndex",lastIndex);
}
java.util.Date now = new java.util.Date();
long lapse = (now.getTime() - lastDate.getTime()) / 1000;
if(lapse > interval){
long idx = Long.parseLong(lastIndex) + 1;
lastIndex = String.valueOf(idx);
application.setAttribute("lastIndex",lastIndex);
application.setAttribute("lastDate",now);
}
lastIndex = "00" + lastIndex;
lastIndex = lastIndex.substring(lastIndex.length() - 2);
String url = prefix + lastIndex + "." + ext;
try{
String path = application.getRealPath(url);
java.io.File file = new java.io.File(path);
if(!file.exists()){
application.setAttribute("lastIndex","01");
lastIndex = "01";
url = prefix + lastIndex + "." + ext;
}
}
catch(Exception ex){
application.setAttribute("lastIndex","01");
}
%>