📄 pointyuefen.java
字号:
/*
*
*/
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import java.util .Date ;
import javax.servlet.http.*;
/**
*
*
* @author Zhu Ke Jun
*/
public class PointYuefen extends HttpServlet{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
HtmlOut htmlOut = new HtmlOut (response);
//身份验证:
// 得到名字和口令
String name = CommonMethods.getParameterValue (request,"Name");
String pass = CommonMethods.getParameterValue (request,"Password");
if(name!=null&&pass!=null){
htmlOut.addCookie ("username",name);
htmlOut.addCookie ("password",pass);
}
else{//other we get it by cookie;
name = CommonMethods.GetUserName(request);
pass = CommonMethods.GetUserPass(request);
}
Person p=new Person();
p.setName (name);
if( p.getName ()==null || (!p.checkPassword(pass))
||(!p.IsSuperMan ()&&!p.IsManager ()) )
{
htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
"请先登录!","/manage/");
htmlOut.outHtml();
return;
}
/*------------------------------------------*/
String sFile = CommonMethods.sLogPath;//文件
sFile=sFile+"access.log" ;
File file;
file=new File(sFile);
FileReader freader;//读取文件
try
{
freader = new FileReader(sFile);
}catch(FileNotFoundException e)
{
System.out .print ("file can not read1");
return ;
}
BufferedReader in= new BufferedReader(freader);
boolean flag;
int yuefenpoint[];
yuefenpoint=new int[12];
flag=true;
AnalyzeString analyze;
analyze=new AnalyzeString ();
int j=0;
for(j=0;j<12;j++)
{
yuefenpoint[j]=0;
}
String templine="",page,time,ip;
/*------------------------------------------*/
//按月份对访问人数统计
String nian = request.getParameter("nian");
Calendar calendar;
calendar=Calendar.getInstance ();
if(nian==null)
{
nian=String.valueOf(calendar.get (calendar.YEAR ));
}
String t,yue="";
while(flag)
{
try{
templine=in.readLine();
}catch(Exception e){}
if(templine==null)
{flag=false;
System.out .println ("ok");
break;}
analyze.getstring (templine);
//System.out .println (analyze.gettime ());
analyze.getstring (templine);
page=analyze.getpage ();
time=analyze.gettime ();
ip=analyze.getip ();
if(page.compareTo ("null")!=0&&time.compareTo ("null")!=0&&ip.compareTo ("null")!=0)
{
t=analyze.gettime ().substring (3,11);
for(int k=0;k<12;k++)
{
if(k==0)
yue="Jan";
if(k==1)
yue="Feb";
if(k==2)
yue="Mar";
if(k==3)
yue="Apr";
if(k==4)
yue="May";
if(k==5)
yue="Jun";
if(k==6)
yue="Jul";
if(k==7)
yue="Aug";
if(k==8)
yue="Sep";
if(k==9)
yue="Oct";
if(k==10)
yue="Nov";
if(k==11)
yue="Dec";
if(t.compareTo (yue+"/"+nian)==0)
{
yuefenpoint[k]=yuefenpoint[k]+1;
break;
}
}
}
}
try{
freader.close ();
in.close ();
}catch(Exception e){}
//所有栏目的访问总数
double allpoint=0;
for(j=0;j<12;j++)
{
allpoint=allpoint+yuefenpoint[j];
}
//计算上下年
String Snian,Xnian;
Snian=String.valueOf(Integer.parseInt (nian)-1);
Xnian=String.valueOf(Integer.parseInt (nian)+1);
//摸版替换
TemplateList tempList = CommonMethods.getpointyuefenTemplate();
SingleTemplate st;
st = tempList.searchTemplate("ROOT");
if(st==null){
htmlOut.setErrorID (htmlOut.SINGLE_TEMPLATE_NOTFIND ,
"","模板错误"
,"Login");
htmlOut.outHtml ();
return ;
}
int nKey = st.getKeyNum ();
String sKey ;
for(int i=0;i<nKey;i++){
htmlOut.addString (st.getStringAt (i));
sKey = st.getKeyAt (i);
if( sKey .compareTo("cgi-path")==0 )
htmlOut.addString (CommonMethods.sHostNameCGI);
if( sKey .compareTo("上年")==0 )
htmlOut.addString (Snian);
if( sKey .compareTo("下年")==0 )
htmlOut.addString (Xnian);
if( sKey.compareTo("内容")==0 )
makeContents(tempList,htmlOut,yuefenpoint,nian,allpoint);
}
htmlOut.addString(st.getEndString());
htmlOut.outHtml ();
}
//时段列表内容
public void makeContents(TemplateList tempList,HtmlOut desHtml,int yuefenpoint[],String nian,double allpoint)
{
SingleTemplate st0,st1;
st0 = tempList.searchTemplate("列表");
if(st0==null)
return;
st1 = tempList.searchTemplate("单支");
if(st1==null)
return;
int i1,i2;
for(i1=0;i1<st0.getKeyNum();i1++)
{
desHtml.addString(st0.getStringAt(i1));
if(st0.getKeyAt(i1).compareTo("cgi-path")==0){
desHtml.addString(CommonMethods.sHostNameCGI);}
if(st0.getKeyAt(i1).compareTo("全部")==0)
{
for(int i=0;i<12;i++)
{
for(i2=0;i2<st1.getKeyNum();i2++)
{
desHtml.addString(st1.getStringAt(i2));
if(st1.getKeyAt(i2).compareTo("cgi-path")==0){
desHtml.addString(CommonMethods.sHostNameCGI);}
if(st1.getKeyAt(i2).compareTo("月份")==0)
desHtml.addString(nian+"年"+String.valueOf (i+1)+"月");
if(st1.getKeyAt(i2).compareTo("访问人数")==0)
desHtml.addString(String.valueOf(yuefenpoint[i]));
if(st1.getKeyAt(i2).compareTo("比例")==0)
{
if(allpoint==0)
desHtml.addString ("0");
else
desHtml.addString(CommonMethods.FormatDouble (yuefenpoint[i]*100/allpoint,2));
}
if(st1.getKeyAt(i2).compareTo("统计图")==0)
{
if(allpoint==0)
desHtml.addString ("0");
else
desHtml.addString(CommonMethods.FormatDouble (yuefenpoint[i]*100*3/allpoint,0).substring (0,CommonMethods.FormatDouble (yuefenpoint[i]*100*3/allpoint,0).indexOf(".")));
}
}
desHtml.addString(st1.getEndString());
}
}
}
desHtml.addString(st0.getEndString());
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request,response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -