⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pointxingqi.java

📁 JAVA邮件系统
💻 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 PointXingqi 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 xingqipoint[];
		xingqipoint=new int [7];
		flag=true;
		AnalyzeString analyze;
		analyze=new AnalyzeString ();
		int j=0;
		for(j=0;j<7;j++)
		{
			xingqipoint[j]=0;
		}
		String templine="",page,time,ip;
		/*------------------------------------------*/
		
		//按星期对访问人数统计
		Calendar calendar;
		calendar=Calendar.getInstance ();
		String xingqi[][];
		xingqi=new String[7][2];
		xingqi[0][0]="1";xingqi[0][1]="星期日";
		xingqi[1][0]="2";xingqi[1][1]="星期一";
		xingqi[2][0]="3";xingqi[2][1]="星期二";
		xingqi[3][0]="4";xingqi[3][1]="星期三";
		xingqi[4][0]="5";xingqi[4][1]="星期四";
		xingqi[5][0]="6";xingqi[5][1]="星期五";
		xingqi[6][0]="7";xingqi[6][1]="星期六";
		String t,nian,yue,ri;
		int Inian,Iyue=0,Iri,week;
		
		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 (0,11);
				ri=t.substring(0,2);
				yue=t.substring(3,6);
				nian=t.substring(7,11);
				Inian=Integer.parseInt (nian);
				Iri=Integer.parseInt (ri);
				if(yue.compareTo ("Jan")==0)
					Iyue=0;
				if(yue.compareTo ("Feb")==0)
					Iyue=1;
				if(yue.compareTo ("Mar")==0)
					Iyue=2;
				if(yue.compareTo ("Apr")==0)
					Iyue=3;
				if(yue.compareTo ("May")==0)
					Iyue=4;
				if(yue.compareTo ("Jun")==0)
					Iyue=5;
				if(yue.compareTo ("Jul")==0)
					Iyue=6;
				if(yue.compareTo ("Aug")==0)
					Iyue=7;
				if(yue.compareTo ("Sep")==0)
					Iyue=8;
				if(yue.compareTo ("Oct")==0)
					Iyue=9;
				if(yue.compareTo ("Nov")==0)
					Iyue=10;
				if(yue.compareTo ("Dec")==0)
					Iyue=11;
				calendar.set (Inian,Iyue,Iri);
				week=calendar.get (calendar.DAY_OF_WEEK );
				for(int k=0;k<7;k++)
				{
				if(week==k+1)
				{
					xingqipoint[k]=xingqipoint[k]+1;
					break;
				}
				}
				}
		}
		try{
			freader.close ();
			in.close ();
		}catch(Exception e){}
		//所有栏目的访问总数
		double allpoint=0;
		for(j=0;j<7;j++)
		{
			allpoint=allpoint+xingqipoint[j];
		}
		//摸版替换
		TemplateList tempList = CommonMethods.getpointxingqiTemplate();
		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 )
				makeContents(tempList,htmlOut,xingqipoint,xingqi,allpoint);
		}
		htmlOut.addString(st.getEndString());
		htmlOut.outHtml ();
	}
	 //时段列表内容
	public void makeContents(TemplateList tempList,HtmlOut desHtml,int xingqipoint[],String xingqi[][],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<7;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(xingqi[i][1]);
   				    	if(st1.getKeyAt(i2).compareTo("访问人数")==0)
   				    	desHtml.addString(String.valueOf(xingqipoint[i]));
   				    	if(st1.getKeyAt(i2).compareTo("比例")==0)
						{
							if(allpoint==0)
								desHtml.addString ("0");
							else 
   				    	desHtml.addString(CommonMethods.FormatDouble (xingqipoint[i]*100/allpoint,2));
						}
   				    	if(st1.getKeyAt(i2).compareTo("统计图")==0)
						{
							if(allpoint==0)
								desHtml.addString ("0");
							else 
   				    	desHtml.addString(CommonMethods.FormatDouble (xingqipoint[i]*100*4/allpoint,0).substring (0,CommonMethods.FormatDouble (xingqipoint[i]*100*4/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 + -