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

📄 trainresult.java

📁 JAVA邮件系统
💻 JAVA
字号:
//列车查询一极结果 
import java.io.*;
import java.text.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 * 
 *
 * @author zhukejun
 */

public class TrainResult extends HttpServlet {
	public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
      
		HtmlOut htmlOut = new HtmlOut (response);
       

		// 得到名字
		String pass;
		Person person = new Person();
		person.setName (CommonMethods.GetUserName(request));
		pass = CommonMethods.GetUserPass (request);
		person.setPassword ( pass );
		if( person.getName ()==null || (!person.checkPassword(pass)) )
		{
	    	htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
								"请先登录!","Login?action=reLog");
			htmlOut.outHtml();
			return;
		}
		
		String r1,r2,train_id,e_station,s_station,zm;
		//r1为查询方式
		r1=CommonMethods.getParameterValue(request,"R1");
		//r2为始发站和终点站的选择
		r2=CommonMethods.getParameterValue(request,"R2");
		train_id=CommonMethods.getParameterValue(request,"train_id");
		e_station=CommonMethods.getParameterValue(request,"dzm");
		s_station=CommonMethods.getParameterValue(request,"fzm");
		zm=CommonMethods.getParameterValue(request,"zm");
		String queryString="",sKey;
		ResultSet rs;
		SingleTemplate st;
		DBOperater DB = new DBOperater ("train");
		int nKey,i;
		String temp="";
		TemplateList tempList;
		boolean flag=false;
		String id,end_station,start_station,start_time,end_time,auto,range,on_time,off_time;
		//车次查询
		if(r1.compareTo ("V1")==0)
		{
			tempList = CommonMethods.gettrain1Template ();
			if( tempList == null ){
				htmlOut.setErrorID (htmlOut.TEMPLATE_NOTFIND ,""
								 ,"gettrain1Template error","TrainSearch");
				htmlOut.outHtml ();
				return;
				}
			st = tempList.searchTemplate("ROOT");
			queryString="select id,interval,start_station,end_station,start_time,end_time,auto from train_id where id like '[kKyYgGzZtTsS]"
						+CommonMethods.DealWithSQLParameter(train_id)+"' or id='"+CommonMethods.DealWithSQLParameter(train_id)+"'";
			rs=DB.executeQuery (queryString);
			if(rs!=null)
			{
				try{
					while(rs.next ())
					{
						id=rs.getString (1).trim ();
						range=rs.getString (2).trim ();
						start_station=rs.getString (3).trim ();
						end_station=rs.getString (4).trim ();
						start_time=rs.getString (5).trim ();
						end_time=rs.getString (6).trim ();
						auto=rs.getString (7).trim ();
						flag=true;
						temp=temp+"<tr align=center bgcolor=#E3E5E5>"+"<td>"+"<a href=TrainResult1?auto="+auto+" target=_blank>"+id+"</a>"+"</td>"+
							 "<td>"+start_station+"</td>"+
							 "<td>"+start_time+"</td>"+
							 "<td>"+end_station+"</td>"+
							 "<td>"+end_time+"</td>"+
							 "<td>"+range+"</td>"+"</tr>";
					
					}
					if(flag==false)
					{
						htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
								"没有您要的信息!"
								,"TrainSearch" );
						DB.close ();
						htmlOut.outHtml ();
						return;
					}
					nKey = st.getKeyNum ();
						for(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(temp);
									
						}
						htmlOut.addString (st.getEndString () );
						htmlOut.outHtml();
				}catch(Exception e){
						 } 
			}
		  DB.close ();
		}
		//站站查询
		if(r1.compareTo ("V2")==0)
		{
			
			tempList = CommonMethods.gettrain1aTemplate ();
			if( tempList == null ){
				htmlOut.setErrorID (htmlOut.TEMPLATE_NOTFIND ,""
								 ,"gettrain1Template error","TrainSearch");
				htmlOut.outHtml ();
				return;
				}
			st = tempList.searchTemplate("ROOT");
			queryString="SELECT a.id, a.start_station, a.start_time, b.on_time, c.off_time,"+ 
							"a.end_station, a.end_time, a.auto "+
							"FROM train_id a, train_info b, train_info c "+
							"WHERE a.auto IN (SELECT DISTINCT (a.auto) FROM Train_info a,"+ 
							"Train_info b WHERE a.station = '"+CommonMethods.DealWithSQLParameter(s_station)+
							"' AND b.station = '"+CommonMethods.DealWithSQLParameter(e_station)+"' "+ 
							"AND a.auto = b.auto AND a.stationno < b.stationno) "+ 
							"AND a.auto = b.auto AND b.station = '"+CommonMethods.DealWithSQLParameter(s_station)+"' "+ 
							"AND a.auto = c.auto AND c.station = '"+CommonMethods.DealWithSQLParameter(e_station)+"' ORDER BY b.on_time";
			rs=DB.executeQuery (queryString);
			if(rs!=null)
			{
				try{
					while(rs.next ())
					{
						id=rs.getString (1).trim ();
						start_station=rs.getString (2).trim ();
						start_time=rs.getString (3).trim ();
						on_time=rs.getString (4).trim ();
						off_time=rs.getString (5).trim ();
						end_station=rs.getString (6).trim ();
						end_time=rs.getString (7).trim ();
						auto=rs.getString (8).trim ();
						flag=true;
						temp=temp+"<tr align=center bgcolor=#E3E5E5>"+"<td>"+"<a href=TrainResult1?auto="+auto+" target=_blank>"+id+"</a>"+"</td>"+
							 "<td>"+start_station+"</td>"+
							 "<td>"+start_time+"</td>"+
							 "<td>"+on_time+"</td>"+
							 "<td>"+off_time+"</td>"+
							 "<td>"+end_station+"</td>"+
							 "<td>"+end_time+"</td>"+"</tr>";
					
					}
					if(flag==false)
					{
						htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
								"没有您要的信息!"
								,"TrainSearch" );
						DB.close ();
						htmlOut.outHtml ();
						return;
					}
					nKey = st.getKeyNum ();
						for(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 ("start")==0)
								htmlOut.addString(s_station);
							if(sKey.compareTo ("end")==0)
								htmlOut.addString(e_station);
							if(sKey.compareTo ("内容")==0)
							htmlOut.addString(temp);
									
						}
						htmlOut.addString (st.getEndString () );
						htmlOut.outHtml();
				}catch(Exception e){
						 } 
			}
		  DB.close ();
			
			
			
		}
		//车站查询
		if(r1.compareTo ("V3")==0)
		{
			tempList = CommonMethods.gettrain1Template ();
			if( tempList == null ){
				htmlOut.setErrorID (htmlOut.TEMPLATE_NOTFIND ,""
								 ,"gettrain1Template error","TrainSearch");
				htmlOut.outHtml ();
				return;
				}
			st = tempList.searchTemplate("ROOT");
			if(r2.compareTo ("V1")==0)
			queryString="select id,interval,start_station,end_station,start_time,end_time,auto from train_id where start_station='"
						+CommonMethods.DealWithSQLParameter(zm)+"' order by id";
			if(r2.compareTo ("V2")==0)
			queryString="select id,interval,start_station,end_station,start_time,end_time,auto from train_id where end_station='"
						+CommonMethods.DealWithSQLParameter(zm)+"' order by id";
			rs=DB.executeQuery (queryString);
			if(rs!=null)
			{
				try{
					while(rs.next ())
					{
						id=rs.getString (1).trim ();
						range=rs.getString (2).trim ();
						start_station=rs.getString (3).trim ();
						end_station=rs.getString (4).trim ();
						start_time=rs.getString (5).trim ();
						end_time=rs.getString (6).trim ();
						auto=rs.getString (7).trim ();
						flag=true;
						temp=temp+"<tr align=center bgcolor=#E3E5E5>"+"<td>"+"<a href=TrainResult1?auto="+auto+" target=_blank>"+id+"</a>"+"</td>"+
							 "<td>"+start_station+"</td>"+
							 "<td>"+start_time+"</td>"+
							 "<td>"+end_station+"</td>"+
							 "<td>"+end_time+"</td>"+
							 "<td>"+range+"</td>"+"</tr>";
					
					}
					if(flag==false)
					{
						htmlOut.setErrorID (htmlOut.SHOW_SIMPLE_MESSAGE ,"",
								"没有您要的信息!"
								,"TrainSearch" );
						DB.close ();
						htmlOut.outHtml ();
						return;
					}
					nKey = st.getKeyNum ();
						for(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(temp);
									
						}
						htmlOut.addString (st.getEndString () );
						htmlOut.outHtml();
				}catch(Exception e){
						 } 
			}
		  DB.close ();
			
		}
		
		
		
	}
	
	public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
		 doGet(request,response);
	}
}

⌨️ 快捷键说明

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