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

📄 ecmlanque.java

📁 IBM AGLET及JAVA实现的电子商务系统源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

import java.io.*;
import java.net.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import com.ibm.aglet.*;


public class ecmLanQue extends HttpServlet {		
	boolean isConnect;
	int disRecords=0;			 ///分页显示时记录所在位置
	int totalRecords=100;        ///查询所得记录总数
	Thread recordFilter;
	
	ResultSet rs;
	ServerApp server=new ServerApp();
	AgletProxy[] p=new AgletProxy[10];	//uesed for the master
	AgletProxy finderProxy;
	AgletProxy finder;
	tableSql t ;	
	AgletContext cxt=null;
	String[] dest=new String[10];        ///uesed for 全国各省 address
	transient AgletProxy[] remoteProxy=new AgletProxy[10] ;///remoteProxy代理slave
	//FutureReply[] future=new FutureReply[10];
	Object[] result=new Object[10];
	int order=0;        ///i used for the order of remoteProxy
	String[][][] records=new String[10][][] ;//uese for save the queryed result from server
	String opState;     //control operation state
	String[][] recordsLoc;
	String[][] recordsQuery;
	boolean filter;     ////是否过滤记录
	boolean range=true;      ///是否周期查询,缺省为周期
	String isCnt="connect";
	int pp=0;
	String qtmp="";
	int qleng=0;
			
	public void init(ServletConfig conf) throws ServletException {
		String fdest;
		super.init(conf);
		try{
			
			if (cxt==null){					
				cxt=server.initStart();
			}
			////////
			
			t = new tableSql("Sysdb");
			finder=server.startAglet(cxt, "ecmAglet.finderProxy");
			/////派遣finderProxy到finder server上获得所选主机ip,port
			ResultSet rrs=t.recordSql("select * from fndConfig where fndConfig.server='e_commerce' ");						
			while (rrs.next()){
				fdest="atp://"+rrs.getString("address")+":"+rrs.getString("port");
				System.out.println("get the finderServer url and port are:"+fdest);
				URL finderUrl=new URL(fdest);
				finderProxy=finder.dispatch(finderUrl);
			}
			///获取server主机ip,port
			Object finderResult=finderProxy.sendAsyncMessage(new Message("sendQuery","get finder information")).getReply();	
			dest=(String[])finderResult;
			//////////
			//dest[0]="202.115.17.128:500";
			//dest[0]="202.115.17.130:500";
			//dest[0]="202.115.17.129:500";
		}//end try
		catch (InvalidAgletException ex) {
	   			ex.printStackTrace();
		} 
		catch (Exception ex) {
	   			ex.printStackTrace();
		}
	}///end function	
	
	
	public void service(HttpServletRequest req,HttpServletResponse resp)
				throws ServletException,IOException,NullPointerException{
		String[] query=new String[2];
		
		
		ServletOutputStream out=resp.getOutputStream();
		resp.setContentType("text/html");
		//response.setContentType("contentType=text/html;charset=gb2312");

		//WatchParameters(req,out);
		opState=req.getParameter("OpType");
		
		String next="向后翻页";
		String pre="向前翻页";

		if (disRecords<=totalRecords ){	
			if (disRecords<0)
				disRecords=0;
			if (opState!=null){
				//System.out.println(new String(opState.getBytes("GBK"),"ISO8859_1"));			
				if ( opState.equals( new String(pre.getBytes("GBK"),"ISO8859_1") ) && disRecords>0 ) {				
					disRecords=disRecords-8;
					isConnect=false;
				}
				else if ( opState.equals( new String(next.getBytes("GBK"),"ISO8859_1") )  ){
					//out.println("next");
					disRecords=disRecords+8;
					isConnect=false;
				}
				else if (opState.equals("add")){								
					isConnect=false;
				}
				else if (opState.equals("connect")){
					//out.println("connect");	
					isConnect=true;
					System.out.println("opstate is connect and isConnect values:"+isConnect); 
					opState=""; ///恢复成缺省值
				}
			}
		}///end if
		///////////////
		String submit=req.getParameter("Submit");
		if (submit!=null){        ////若执行查询则从新连接数据库,派遣dbProxy
			isCnt="connect";
			submit=null;
			
			/*String srange=req.getParameter("range");
			if ( new String(srange.getBytes("ISO8859_1"),"GBK").equals("周期搜索") )
				range=true;
			else 
				range=false;
			*/
			System.out.println("the range is :"+range);	
			if (recordsQuery!=null){
				System.out.println("clear recordsQuery");
				for (int a=0;a<10;a++)
					for (int b=0;b<recordsQuery[1].length;b++)
						//for (int c=0;c<=recordsQuery[a][b].length;c++)
							recordsQuery[a][b]="";
			}
			if (recordsLoc!=null){
				System.out.println("clear recordsLoc");
				for (int d=0;d<recordsLoc.length;d++)
					for (int e=0;e<recordsLoc[1].length;e++)
						recordsLoc[d][e]="";
			}
			if (records!=null){
				System.out.println("clear records");
				for (int f=0;f<10;f++)
					if (records[f]!=null){
						for (int g=0;g<records[f].length;g++)
							for (int h=0;h<records[f][1].length;h++)
								records[f][g][h]="";
					}
			}
			if (result!=null){
				System.out.println("clear result");
				for (int i=0;i<10;i++)
					result[i]=null;
			}
			//out.println("submit value:"+submit);
		//}
			System.out.println("isCnt value:"+isCnt);
		///////////////
		//if (isCnt.equals("connect")){	
			//else if ( opState.equals( new String(next.getBytes("GBK"),"ISO8859_1") )  ){
			//String cq=new String(req.getParameter("KEYWORDS").getBytes("ISO8859_1"),"GBK");
			//out.println(new String(cq.getBytes("GBK"),"ISO8859_1") );
			//out.println("type is :"+type);///type ---->ISO (used for html display)
			//System.out.println("tttttt"+ new String(type.getBytes("ISO8859_1"),"GBK") );///ISO--->GBK
			
			
			
			String type=req.getParameter("goodsname");
			String mode=req.getParameter("mode");
			if ( new String(mode.getBytes("ISO8859_1"),"GBK").equals("周期搜索") )
				mode="repeate";
			else 
				mode="once";
			if ( new String(type.getBytes("ISO8859_1"),"GBK").equals("彩电") )
				type="caidian";
			else  if ( new String(type.getBytes("ISO8859_1"),"GBK").equals("冰箱") )
				type="bingxiang";
			//else  if ( new String(type.getBytes("ISO8859_1"),"GBK").equals("外语") )
			//	type="language";				 
			else  if ( new String(type.getBytes("ISO8859_1"),"GBK").equals("电脑") )
				type="computer";
			System.out.println("the type is:"+type);
			///////////////
			
			String model=req.getParameter("model");
			String price=req.getParameter("price");
			String amount=req.getParameter("amount");
			System.out.println("price is:"+price);
			/*if (price.equals(""))
				price="0";
			if (amount.equals(""))
				amount="0";*/
			//query=type+"',"+req.getParameter("model")+"',"+req.getParameter("price")+"',"+req.getParameter("amoount");
			
			//qtmp="where goodsname='"+type+"' and model='"+model+"'";
			qtmp=" where goodsname='"+type+"'";
			if (!model.equals(""))
				qtmp=qtmp+" and model='"+model+"'";
			if (!price.equals(""))
				qtmp=qtmp+" and model"+price;
			else price="0";
			if (!amount.equals(""))
				qtmp=qtmp+" and amount"+amount;
			else amount="0";
			System.out.println("the qtmp is:"+qtmp);
			
			//String servetime=Double(System.currentTimeMillis()+70000000).toString();
			query[0]=mode;
			//if (mode.equals("repeate"))
				//query[1]="'"+type+"',"+"'"+model+"',"+"'"+price+"',"+"'"+amount+"','70000000'";
			query[1]="'"+type+"',"+"'"+model+"',"+"'"+price+"',"+"'"+amount+"'";
			//else 
				//query[1]="'"+type+"',"+"'"+model+"',"+"'"+price+"',"+"'"+amount+"','2000'";
				
			System.out.println("*******get message from the guest are:"+query[1]); 
				
			//String query2="select * from goods where goodsname='"+type+"' and model='"+model+"'";
			
			t = new tableSql("Ecmdb");
			
			int kk=dest.length;		
			////////	进行周期查询	
			if (range){
				try{
					p[order]=server.startAglet(cxt, "ecmAglet.ecmClient");
					p[order].sendAsyncMessage(new Message("dispatch",dest));
					System.out.println("i have dispach ecmProxy");
					p[order].sendAsyncMessage(new Message("sendQuery",query));
					System.out.println("i have send mesage to ecmProxy");
				}
				catch (Exception ex){
					ex.printStackTrace();
				}
				/*
				filter=true;
				////周期检测看是否有新的信息
				recordFilter=new Thread(ecmLanQue.this);

⌨️ 快捷键说明

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