📄 pointriqilanmu.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 PointRiqiLanmu 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 riqipoint[];
riqipoint=new int [31];
flag=true;
AnalyzeString analyze;
analyze=new AnalyzeString ();
int j=0;
for(j=0;j<31;j++)
{
riqipoint[j]=0;
}
String templine="",page,time,ip;
/*------------------------------------------*/
//按日期和栏目对访问人数统计
String nian = request.getParameter("nian");
String yue = request.getParameter("yue");
String lanmu=CommonMethods.DealWithGBCodeOfRequest(request.getParameter ("lanmu"));
Calendar calendar;
calendar=Calendar.getInstance ();
if(lanmu==null)
lanmu="/b/Default.htm*主页";
String lanmuming=lanmu.substring(lanmu.indexOf ("*")+1,lanmu.length ());
lanmu=lanmu.substring (0,lanmu.indexOf ("*"));
if(nian!=null&&yue!=null)
{
calendar.set (Integer.parseInt (nian),Integer.parseInt(yue)-1,1);
calendar.add (calendar.MONTH ,1);
calendar.add (calendar.DATE ,-1);
}
else
{
calendar.set (calendar.DAY_OF_MONTH ,1);
calendar.add (calendar.MONTH ,1);
calendar.add (calendar.DATE ,-1);
}
int Inian,Iyue,Iri,datecount;
Inian=calendar.get (calendar.YEAR );
Iyue=calendar.get (calendar.MONTH );
datecount=calendar.get (calendar.DAY_OF_MONTH );
String ri;
if(Iyue==0)
yue="Jan";
if(Iyue==1)
yue="Feb";
if(Iyue==2)
yue="Mar";
if(Iyue==3)
yue="Apr";
if(Iyue==4)
yue="May";
if(Iyue==5)
yue="Jun";
if(Iyue==6)
yue="Jul";
if(Iyue==7)
yue="Aug";
if(Iyue==8)
yue="Sep";
if(Iyue==9)
yue="Oct";
if(Iyue==10)
yue="Nov";
if(Iyue==11)
yue="Dec";
while(flag)
{
try{
templine=in.readLine();
}catch(Exception e){}
if(templine==null)
{flag=false;
System.out .println ("ok");
break;}
//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)
for(int k=0;k<datecount;k++)
{
Iri=k+1;
if(Iri<10)
ri="0"+Iri;
else
ri=String.valueOf (Iri);
if(time.indexOf (ri+"/"+yue+"/"+Inian)!=-1&&page.indexOf (lanmu)!=-1)
{
riqipoint[k]=riqipoint[k]+1;
break;
}
}
}
try{
freader.close ();
in.close ();
}catch(Exception e){}
//所有栏目的访问总数
double allpoint=0;
for(j=0;j<datecount;j++)
{
allpoint=allpoint+riqipoint[j];
}
//计算上下月
calendar.set (Inian,Iyue,1);
String Snian,Syue,Xnian,Xyue;
calendar.add (calendar.MONTH ,-1);
Snian=String.valueOf(calendar.get (calendar.YEAR ));
Syue=String.valueOf(calendar.get (calendar.MONTH )+1);
calendar.add (calendar.MONTH ,2);
Xnian=String.valueOf(calendar.get (calendar.YEAR ));
Xyue=String.valueOf(calendar.get (calendar.MONTH )+1);
//摸版替换
TemplateList tempList = CommonMethods.getpointriqilanmuTemplate();
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 (lanmuming);
if( sKey .compareTo("栏目")==0 )
htmlOut.addString (lanmu+"*"+lanmuming);
if( sKey .compareTo("上年")==0 )
htmlOut.addString (Snian);
if( sKey .compareTo("上月")==0 )
htmlOut.addString (Syue);
if( sKey .compareTo("下年")==0 )
htmlOut.addString (Xnian);
if( sKey .compareTo("下月")==0 )
htmlOut.addString (Xyue);
if( sKey.compareTo("内容")==0 )
makeContents(tempList,htmlOut,riqipoint,Inian,Iyue,datecount,allpoint);
}
htmlOut.addString(st.getEndString());
htmlOut.outHtml ();
}
//时段列表内容
public void makeContents(TemplateList tempList,HtmlOut desHtml,int riqipoint[],int Inain,int Iyue,int datecount,double allpoint)
{
int Iri;
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<datecount;i++)
{
Iri=i+1;
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(Inain+"年"+String.valueOf (Iyue+1)+"月"+Iri+"日");
if(st1.getKeyAt(i2).compareTo("访问人数")==0)
desHtml.addString(String.valueOf(riqipoint[i]));
if(st1.getKeyAt(i2).compareTo("比例")==0)
{
if(allpoint==0)
desHtml.addString ("0");
else
desHtml.addString(CommonMethods.FormatDouble (riqipoint[i]*100/allpoint,2));
}
if(st1.getKeyAt(i2).compareTo("统计图")==0)
{
if(allpoint==0)
desHtml.addString ("0");
else
desHtml.addString(CommonMethods.FormatDouble (riqipoint[i]*100*6/allpoint,0).substring (0,CommonMethods.FormatDouble (riqipoint[i]*100*6/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 + -