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

📄 showpollute.java

📁 JAVA邮件系统
💻 JAVA
字号:
/* 
 *
 */

import java.io.*;
import java.text.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ShowPollute extends HttpServlet {

    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
		String sPathName= new String ();
		String sFileName=new String ();
	    Calendar calendar = Calendar.getInstance ();
       
		//查出当前库中最新空气质量数据数据
		DBOperater DB = new DBOperater ("air_pollute");
		ResultSet rs = DB.executeQuery ("select input_date from air_pollute ORDER BY input_date DESC");
		if(rs!=null){
			try{
				if( rs.next () )
				{
					calendar.setTime(rs.getDate (1));
				}
			}
			catch(Exception e){
				DB.close ();
				return;
			}
		}
		DB.close ();
		sPathName=CommonMethods.sHtmlPath +"pollute";
		File fWeatherPath=new File (sPathName);
		if (!fWeatherPath.exists() || !fWeatherPath.isDirectory() )
		{  	try{
				 fWeatherPath.mkdirs();
			}catch(Exception e){
			return;
			}
		}
       String sTime="";
	   sTime +=calendar.get(calendar.YEAR );
	   sTime +=(calendar.get(calendar.MONTH )+1);
	   sTime +=calendar.get(calendar.DATE );
	   sFileName=sPathName+"/"+sTime+".htm";
       File  fWeatherFile=new File (sFileName);
	  // RandomAccessFile fWeatherHtmlFile= null  ;
	 
	   //判断本日天气的静态文件是否存在,如果不存在则创建此文件
		if (!fWeatherFile.exists ()){
			String sYear = new String ();
			String sMonth = new String ();
			String sDay = new String ();
			/////////////////////////////
			//得到空气质量显示的模板
		  	TemplateList tempList=CommonMethods.getShowPolluteTemplate ();
			SingleTemplate st;
			st = tempList.searchTemplate ("ROOT");
		    
			if(st==null)
			{
				 return ;
			}
			int nKey = st.getKeyNum ();
			String sPolluteShow="";
			String sKey= new String ();
			//int nYear,nMonth,nDay;
			for(int i=0;i<nKey;i++){
				sPolluteShow+=st.getStringAt (i);
				sKey = st.getKeyAt (i);
				if( sKey.compareTo("cgi-path")==0 )
					sPolluteShow+= (CommonMethods.sHostNameCGI);
			
				if (sKey.compareTo ("年")==0)
					sPolluteShow+=calendar.get(calendar.YEAR );
				if (sKey.compareTo ("月")==0)
					sPolluteShow+=(calendar.get(calendar.MONTH )+1);
				if (sKey.compareTo ("日")==0)
					sPolluteShow+=calendar.get(calendar.DATE );
				if (sKey.compareTo ("空气质量")==0)
				{
					//查找并替换子模板
					SingleTemplate st1;
					st1 = tempList.searchTemplate ("空气");
					int nKey1 = st1.getKeyNum ();
					if(st1==null)
					{
						return;
					}
					String sCity= new String ();
					int po_index;
					String chiefly=new String ();
					String air_level=new String ();
					String air_status = new String ();
					String sKey1 = new String ();
					DBOperater DB1 = new DBOperater ("air_pollute");
		            
					//ResultSet rs1 = DB1.executeQuery ("select city_name,po_index,chiefly,air_level,air_status from  air_pollute Where input_date > " +calendar.getTime ());
					ResultSet rs1= DB1.executeQuery ("select distinct city_name,po_index,chiefly,air_level,air_status from  air_pollute ");
					if(rs1!=null){
						try{
							while( rs1.next () )
							{	
								sCity = rs1.getString (1);
								po_index = rs1.getInt  (2);
								chiefly = rs1.getString (3);
								air_level = rs1.getString (4);
								air_status = rs1.getString (5);
								if (sCity==null)
									sCity = "";
								if (chiefly==null)
									chiefly = "";
								if (air_level ==null)
									air_level="";
								if (air_status==null)
									air_status="";
								for (int j=0;j<nKey1;j++)
								{
									sPolluteShow+=st1.getStringAt (j);
									sKey1 = st1.getKeyAt (j);
									if( sKey1.compareTo("cgi-path")==0 )
										sPolluteShow+= (CommonMethods.sHostNameCGI);
									if (sKey1.compareTo ("城市名")==0)
										sPolluteShow+=sCity;
									if (sKey1.compareTo ("指数")==0)
										sPolluteShow+=po_index;
									if (sKey1.compareTo ("污染物")==0)
										sPolluteShow+=chiefly;
									if (sKey1.compareTo ("空气级别")==0)
										sPolluteShow+=air_level;
									if (sKey1.compareTo ("空气质量")==0)
										sPolluteShow+=air_status;
								}
								sPolluteShow+=st1.getEndString ();
							}
						}
						catch(Exception e){
							DB1.close ();
							return;
						}
					}
					DB1.close ();

				}
				
			}
			sPolluteShow+=st.getEndString();
			int fileLength;
			fileLength=sPolluteShow.length();
			byte[] b1=new byte[fileLength];
			b1=sPolluteShow.getBytes ();
			CommonMethods.WriteToDisk (b1,sFileName);
			}
		response.sendRedirect (CommonMethods.sWebRoot  +"pollute/"+sTime+".htm");
	}
	
       public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
		doGet(request,response);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -