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

📄 pointshiduan.java

📁 JAVA邮件系统
💻 JAVA
字号:
/* 
 *
 */
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import java.util .Date ;
import javax.servlet.http.*;
import java.sql.*;
/**
 * 
 *
 * @author Zhu Ke Jun
 */
public class PointShiduan 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 shiduan[];
		shiduan=new int [24];
		flag=true;
		AnalyzeString analyze;
		analyze=new AnalyzeString ();
		int j=0;
		for(j=0;j<24;j++)
		{
			shiduan[j]=0;
		}
		String templine="",page,time,ip;
		/*------------------------------------------*/
		//按时段对访问人数统计
		
		String shijian,begin,end;
		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);
			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<24;k++)
			{
				if(k<10)
				{
					begin="0"+k+":"+"00";
					end="0"+k+";"+"59";
				}
				else
				{
						begin=k+":"+"00";
						end=k+";"+"59";	
				}
			   
				shijian=time.substring(12,17);
				if(shijian.compareTo(begin)>=0&&shijian.compareTo (end)<=0)
				{
					shiduan[k]=shiduan[k]+1;
					break;
				}
			}
			
		}
		try{
			freader.close ();
			in.close ();
		}catch(Exception e){}
		//所有时段的访问总数
		double allpoint=0;
		for(j=0;j<24;j++)
		{
			allpoint=allpoint+shiduan[j];
		}
		//摸版替换
		TemplateList tempList = CommonMethods.getpointshiduanTemplate();
		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,shiduan,allpoint);
		}
		htmlOut.addString(st.getEndString());
		htmlOut.outHtml ();
	}
	 //时段列表内容
	public void makeContents(TemplateList tempList,HtmlOut desHtml,int shiduan[],double allpoint)
	{
		
		String begin,end;
		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<24;i++)
   				  {
				   if(i<10)
					{
						begin="0"+i+":"+"00";
						end="0"+i+";"+"59";
					}
					else
					{
						begin=i+":"+"00";
						end=i+";"+"59";	
					}
				  
   				   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(begin+"-"+end);
   				    	if(st1.getKeyAt(i2).compareTo("访问人数")==0)
   				    	desHtml.addString(String.valueOf(shiduan[i]));
   				    	if(st1.getKeyAt(i2).compareTo("比例")==0)
						{
							if(allpoint==0)
								desHtml.addString ("0");
							else 
   				    	desHtml.addString(CommonMethods.FormatDouble (shiduan[i]*100/allpoint,2));
						}
   				    	if(st1.getKeyAt(i2).compareTo("统计图")==0)
						{
							if(allpoint==0)
								desHtml.addString ("0");
							else 
   				    	desHtml.addString(CommonMethods.FormatDouble (shiduan[i]*100*20/allpoint,0).substring (0,CommonMethods.FormatDouble (shiduan[i]*100*20/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 + -