国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

調用 CGI 腳本

2019-11-18 16:05:46
字體:
來源:轉載
供稿:網友
/*
Learning Wireless java
Help for New J2ME Developers
By Qusay Mahmoud
ISBN: 0-596-00243-2

*/
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

/**
 * An example MIDlet to invoke a CGI script (POST method is used).
 */

public class InvokeCgiMidlet2 extends MIDlet {

   PRivate Display display;

   String url = "http://www.javacourses.com/cgi-bin/pgrade.cgi";

   public InvokeCgiMidlet2() {
      display = Display.getDisplay(this);
   }

   /**
    * Initialization. Invoked when we activate the MIDlet.
    */
   public void startApp() {
      try {
         getGrade(url);
      } catch (IOException e) {
         System.out.println("IOException " + e);
         e.printStackTrace();
      }
   }

   /**
    * Pause, discontinue ....
    */
   public void pauseApp() {
   }

   /**
    * Destroy must cleanup everything.
    */
   public void destroyApp(boolean unconditional) {
   }

   /**
    * Retrieve a grade....
    */

   void getGrade(String url) throws IOException {
      HttpConnection c = null;
      InputStream is = null;
      OutputStream os = null;
      StringBuffer b = new StringBuffer();
      TextBox t = null;
      try {
         c = (HttpConnection)Connector.open(url);
         c.setRequestMethod(HttpConnection.POST);
         c.setRequestProperty("CONTENT-TYPE","application/x-www-form-urlencoded");
         c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Confirguration/CLDC-1.0");
         c.setRequestProperty("Content-Language", "en-CA");
         os = c.openOutputStream();

         // send input
         String str = "name=182016";
         byte postmsg[] = str.getBytes();
         for(int i=0;i<postmsg.length;i++) {
            os.write(postmsg[i]);
         }
         os.flush();
         is = c.openDataInputStream();
         int ch;
         // receive output
         while ((ch = is.read()) != -1) {
            b.append((char) ch);
            System.out.println((char)ch);
         }
         t = new TextBox("Final Grades", b.toString(), 1024, 0);
      } finally {
         if(is!= null) {
            is.close();
         }
         if(os != null) {
            os.close();
         }
         if(c != null) {
            c.close();
         }
      }
      display.setCurrent(t);
   }     
}

(出處:http://m.survivalescaperooms.com)



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 车险| 潮安县| 镇平县| 乐东| 常宁市| 渭南市| 黄石市| 循化| 灯塔市| 仁寿县| 偏关县| 沁阳市| 全州县| 改则县| 泾源县| 井冈山市| 肇庆市| 东阿县| 福安市| 甘孜县| 罗城| 汤原县| 万载县| 永丰县| 南京市| 晋中市| 科技| 油尖旺区| 体育| 延津县| 兰州市| 鹰潭市| 崇仁县| 商丘市| 监利县| 奇台县| 孝义市| 改则县| 二连浩特市| 平果县| 蒲江县|