String logString4 = logString2 + stringDate(gregoriancalendar) + logString1 + ".txt";
saveLog(logHashtable, logString4, logString3);
}
private void saveLog(Hashtable hashtable, String s, String s1)//把日志文件保存在硬盘上
{
synchronized(hashtable.get("log"))
{
try
{
FileWriter filewriter = new FileWriter(s, true);
PrintWriter printwriter = new PrintWriter(filewriter);
printwriter.println(s1);
printwriter.flush();
printwriter.close();
filewriter.close();
}
catch(Exception _ex) { }
}
}
private String getLogString(String s, HttpServletRequest httpservletrequest)
file://取得日志字符串
{
String s1 = httpservletrequest.getRemoteAddr();
file://取得远程的访问者的IP地址
String s2 = httpservletrequest.getHeader("User-Agent");
String s3 = httpservletrequest.getHeader("Referer");
String s4 = """ + s + """;
if(s1 == null)
s1 = "-";
if(s2 == null)
s2 = "-";
else
s2 = """ + s2 + """;
if(s3 == null)
s3 = "-";
else
s3 = """ + s3 + """;
return s1 + " [" + new Date() + "] " + s4 + " " + s3 + " " + s2;
}
private String stringDate(Calendar calendar) file://取得时间戳
{
String s = String.valueOf(calendar.get(1));
String s1 = String.valueOf(calendar.get(2));
if(s1.length() == 1)
s1 = "0" + s1;
s = s + s1;
s1 = String.valueOf(calendar.get(5));
if(s1.length() == 1)
s1 = "0" + s1;
return s + s1;
}
private String getFileByUrl(Hashtable hashtable, String s)
{
for(Enumeration enumeration = hashtable.keys(); enumeration.hasMoreElements();)
file://hashtable的keys()方法返回了哈希表关键字的枚举,enumeration的hasMoreElements()方法测试枚举重是否还有其他元素
{
String s1 = (String)enumeration.nextElement();
file://让s1的值为enumeration的下一个元素值
if(s.equals(hashtable.get(s1)))//如果s的值为s1的值,则
return s1;//返回s1的值
}
return null;
}
private String getFirstSite(Hashtable hashtable)//取得第一个站点的名字
{
String s = (String)hashtable.get("dir");
File file = new File(s);
if(file == null)
return null;
String as[] = file.list();
Vector vector = getGraphFiles(as);
file://设置Vector向量变量来获取图形文件
if(vector.size() == 0)//如果没有图形文件,则返回空值
return null;
else
return getUrl(hashtable, (String)vector.elementAt(0));
}
private String getUrl(Hashtable hashtable, String s)//取得URL
{
String s1 = s.toLowerCase();//设置s1为s的小写形式
for(Enumeration enumeration = hashtable.keys(); enumeration.hasMoreElements();)
{
String s2 = (String)enumeration.nextElement();
if(s1.equals(s2.toLowerCase()))
return (String)hashtable.get(s2);
}
return null;
}
private void outputBanner(String s, Hashtable hashtable, HttpServletResponse httpservletresponse)//输出banner广告
throws IOException//如果有错则抛出IOException错误
{
String s1 = (String)hashtable.get("dir") + s;
httpservletresponse.setHeader("Cache-control", "no-store");
httpservletresponse.setHeader("Pragma", "no-cache");
httpservletresponse.setDateHeader("Expires", 1L);
httpservletresponse.setContentType("image/" + s.substring(s.indexOf(".") + 1));
javax.servlet.ServletOutputStream servletoutputstream = httpservletresponse.getOutputStream();
dumpFile(s1, servletoutputstream);
servletoutputstream.flush();
servletoutputstream.close();