筆記

          way

          2012年2月22日

          最近在網(wǎng)上看到的相關(guān)材料都比較陳舊,也太簡(jiǎn)略,參看了一下其他人的內(nèi)容,針對(duì)Hive2.1.1做點(diǎn)分享:
          1)下載apache-hive-2.1.1-bin.tar.gz

          2)解壓縮,下面的命令行如啟動(dòng)報(bào)錯(cuò),請(qǐng)自行查略Hive啟動(dòng)配置

          3)啟動(dòng)hiveserver2 (非必須,使用jdbc訪問(wèn)的時(shí)候才使用)
          bin目錄下
          hive --service hiveserver2 -p10001來(lái)啟動(dòng)hiveserver2 服務(wù)(默認(rèn)為10000端口)
          nohup hive --service hiverserver2 -p10001可以在后臺(tái)跑
          4)hive腳本運(yùn)行流程
          bin目錄下,使用命令方法為:
          ./hive <parameters> --service serviceName <service parameters>
          舉例:hive --debug :
             查看bin/hive文件
          流程中會(huì)判斷$1=‘--debug’則$DEBUG=‘--debug’
           
          if [ "$DEBUG" ]; then
            if [ "$HELP" ]; then //如還有--help,就會(huì)執(zhí)行debug_help方法。
              debug_help
              exit 0
            else
              get_debug_params "$DEBUG"
              export HADOOP_CLIENT_OPTS="$HADOOP_CLIENT_OPTS $HIVE_MAIN_CLIENT_DEBUG_OPTS"http://設(shè)置HIVE_MAIN_CLIENT_DEBUG_OPTS的參數(shù)中加入debug相應(yīng)參數(shù)
            fi
          fi
          if [ "$SERVICE" = "" ] ; then
            if [ "$HELP" = "_help" ] ; then
              SERVICE="help"
            else
              SERVICE="cli"     //默認(rèn)賦值cli
            fi
          fi
          這個(gè)shell腳本很多變量應(yīng)該是在其他sh文件中定義,其中$SERVICE_LIST就是其他很多sh文件的最開(kāi)始形成的:export SERVICE_LIST="${SERVICE_LIST}${THISSERVICE} "
          hive腳本最后的$TORUN "$@" ,默認(rèn)情況下TORUN其實(shí)就是cli,即執(zhí)行/ext/cli.sh腳本,該腳本中主要是調(diào)用/ext/util/execHiveCmd.sh 來(lái)執(zhí)行最后的CliDriver。
           【shell腳本中的$*,$@和$#
          舉例說(shuō):
          腳本名稱叫test.sh 入?yún)⑷齻€(gè): 1 2 3
          運(yùn)行test.sh 1 2 3后
          $*為"1 2 3"(一起被引號(hào)包住)
          $@為"1" "2" "3"(分別被包住)
          $#為3(參數(shù)數(shù)量)
          即exec $HADOOP jar ${HIVE_LIB}/$JAR $CLASS $HIVE_OPTS "$@" //1
          其中:
          $HADOOP=$HADOOP_HOME/bin/hadoop 【hive腳本中定義HADOOP=$HADOOP_HOME/bin/hadoop】
          $CLASS=org.apache.hadoop.hive.cli.CliDriver【傳入的第一個(gè)參數(shù),在cli.sh中有定義】
          hadoop腳本(2.7.3為例)中最終會(huì)執(zhí)行:
          # Always respect HADOOP_OPTS and HADOOP_CLIENT_OPTS
              HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
              #make sure security appender is turned off
              HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,NullAppender}"
           
              export CLASSPATH=$CLASSPATH
              exec "$JAVA" $JAVA_HEAP_MAX $HADOOP_OPTS $CLASS "$@" //2
          hive的debug參數(shù)就是在啟動(dòng)hive腳本時(shí)放到HADOOP_OPTS中的
          1和2處結(jié)合可得到最終的運(yùn)行命令,查看一下運(yùn)行結(jié)果:ps -ef|grep CliDriver

            /usr/java/jdk1.8.0_101/bin/java -Xmx256m -Djava.net.preferIPv4Stack=true -Dhadoop.log.dir=.. -Dhadoop.log.file=hadoop.log -Dhadoop.home.dir=.. -Dhadoop.id.str=root -Dhadoop.root.logger=INFO,console -Djava.library.path=.. -Dhadoop.policy.file=hadoop-policy.xml -Djava.net.preferIPv4Stack=true -Xmx512m -Dproc_hivecli -XX:+UseParallelGC -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=-Dlog4j.configurationFile=hive-log4j2.properties -Djava.util.logging.config.file=..
            
          -Dhadoop.security.logger=INFO,NullAppender org.apache.hadoop.util.RunJar /yuxh/app/apache-hive-2.*/lib/hive-cli-2.*.jar org.apache.hadoop.hive.cli.CliDriver
          posted @ 2017-03-29 16:01 yuxh 閱讀(1591) | 評(píng)論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2015-09-23 21:14 yuxh 閱讀(4420) | 評(píng)論 (0)編輯 收藏
          appfuse3.5使用Hibernate4.3.6, 而Hibernate日志框架使用了jboss-logging,想在后臺(tái)打出sql的參數(shù)一直無(wú)法生效。
          檢查配置文件,框架里面的兩個(gè)配置文件,src/test/resources/log4j2.xml(單元測(cè)試時(shí)配置),src/main/resources/log4j2.xml(運(yùn)行時(shí)配置)
          搞清log4j2的配置后,各種修改(主要是
            <Logger name="org.hibernate.SQL" level="trace"/>
            <Logger name="org.hibernate.type" level="trace"/>)
          用junit測(cè)試任然無(wú)法打印出真實(shí)參數(shù)。根據(jù)這些實(shí)踐,確定log4j2是使用無(wú)誤生效的,只是org.hibernate這部分的logger一直未起效
          參考國(guó)內(nèi)外網(wǎng)站,一直無(wú)人回答hibernate4的這個(gè)問(wèn)題,有人指出這部分Hibernate官方文檔只是提了一句,一直未更新相關(guān)內(nèi)容。最后有人提到應(yīng)該是 jboss-logging 的LoggerProviders這個(gè)類(lèi)的問(wèn)題,看實(shí)現(xiàn)對(duì)log4j2已經(jīng)做支持。最后發(fā)現(xiàn) jboss-logging使用的是3.2.0.beta,對(duì)比相關(guān)類(lèi)的源代碼,更改為3.2.0.Final,生效!

          P.S 把這個(gè)問(wèn)題提交給Appfuse官網(wǎng),issue APF-1478,作者標(biāo)志為4.0版本修復(fù)。
          posted @ 2015-07-22 14:11 yuxh 閱讀(299) | 評(píng)論 (0)編輯 收藏
          新電腦裝上eclipse4.4.2,導(dǎo)入maven項(xiàng)目之后,依賴庫(kù)總是有很多錯(cuò)誤。最后搜索到可能是eclipse的bug(據(jù)說(shuō)是JAVA_HOME沒(méi)有正確傳遞),查看到eclipse默認(rèn)的是安裝的jre目錄,修改到j(luò)dk目錄下,依賴問(wèn)題解決。
          不過(guò)目前版本仍然沒(méi)有解決pom文件的“Plugin execution not covered by lifecycle configuration”錯(cuò)誤,暫時(shí)忽略不管吧。
          posted @ 2015-06-02 10:27 yuxh 閱讀(332) | 評(píng)論 (0)編輯 收藏
          本打算繼承一個(gè)API中的Parent類(lèi)(Parent繼承自GrandParent類(lèi)),重寫(xiě)其中的service方法,copy了Parent的service方法。不過(guò)發(fā)現(xiàn)Parent的service中也有super.service方法。當(dāng)時(shí)考慮直接調(diào)用GrandParent的service方法。。。未遂(包括反射也不行)。正好看到老外寫(xiě)的一篇文章,翻譯:
          在Son類(lèi)里面寫(xiě)一個(gè)test方法:
          public void test() {
           
          super.test();
           
          this.test();
          }
          反編譯之后:
          public void test()
              {
              
          //    0    0:aload_0         
              
          //    1    1:invokespecial   #2   <Method void Parent.test()>
              
          //    2    4:aload_0         
              
          //    3    5:invokevirtual   #3   <Method void test()>
              
          //    4    8:return          
              }
          使用ASM可以完成對(duì)GrandParent方法的調(diào)用
          public class GrandParent {
              
          public void test() {
                      System.out.println(
          "test of GrandParent");
              }
          }

          public class Parent extends GrandParent{
              
          public void test() {
                  System.out.println(
          "test of Parent");
              }
          }

          public class Son extends Parent{
              
          public void test() {
                  System.out.println(
          "test of Son");
              }
          }
          調(diào)用Son實(shí)例的test方法只會(huì)執(zhí)行Son的test方法。而ASM可以修改class,先寫(xiě)一個(gè)Example類(lèi)繼承Son,重寫(xiě)test方法

           1 import java.io.FileOutputStream;
           2  
           3 import org.objectweb.asm.ClassWriter;
           4 import org.objectweb.asm.MethodVisitor;
           5 import org.objectweb.asm.Opcodes;
           6  
           7 public class ASMByteCodeManipulation extends ClassLoader implements Opcodes {
           8  
           9  public static void main(String args[]) throws Exception {
          10   ClassWriter cw = new ClassWriter(0);
          11   cw.visit(V1_1, ACC_PUBLIC, "Example"null"Son"null);
          12  
          13   // creates a MethodWriter for the (implicit) constructor
          14   MethodVisitor mw = cw.visitMethod(ACC_PUBLIC, "<init>""()V"null,null);
          15   mw.visitVarInsn(ALOAD, 0);
          16   mw.visitMethodInsn(INVOKESPECIAL, "Son""<init>""()V");
          17   mw.visitInsn(RETURN);
          18   mw.visitMaxs(11);
          19   mw.visitEnd();
          20  
          21   // creates a MethodWriter for the 'test' method
          22   mw = cw.visitMethod(ACC_PUBLIC, "test""()V"nullnull);
          23   mw.visitFieldInsn(GETSTATIC, "java/lang/System""out","Ljava/io/PrintStream;");
          24   mw.visitLdcInsn("test of AI3");
          25   mw.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream""println",
          26     "(Ljava/lang/String;)V");
          27   //Call test() of GrandParent
          28   mw.visitVarInsn(ALOAD, 0);
          29   mw.visitMethodInsn(INVOKESPECIAL, "GrandParent""test""()V");
          30   //Call test() of GrandParent
          31   mw.visitVarInsn(ALOAD, 0);
          32   mw.visitMethodInsn(INVOKESPECIAL, "Parent""test""()V");
          33   //Call test() of GrandParent
          34   mw.visitVarInsn(ALOAD, 0);
          35   mw.visitMethodInsn(INVOKESPECIAL, "Son""test""()V");
          36   mw.visitInsn(RETURN);
          37   mw.visitMaxs(21);
          38   mw.visitEnd();
          39  
          40   byte[] code = cw.toByteArray();
          41   FileOutputStream fos = new FileOutputStream("Example.class");
          42   fos.write(code);
          43   fos.close();
          44  
          45   ASMByteCodeManipulation loader = new ASMByteCodeManipulation();
          46   Class<?> exampleClass = loader.defineClass("Example", code, 0,
          47     code.length);
          48   Object obj = exampleClass.newInstance();
          49   exampleClass.getMethod("test"null).invoke(obj, null);
          50  
          51  }
          52 }
          輸出:
          test of AI3
          test of GrandParent
          test of Parent
          test of Son
          看看怎樣實(shí)現(xiàn)的,11行定義一個(gè)新的類(lèi)Example繼承Son。22行,Example重寫(xiě)test方法,先打印“test of AI3”,再分別在29、32、35行調(diào)用GrandParent、Parent、Son的test方法。
           main方法中,45行創(chuàng)建Example的實(shí)例,再用反射調(diào)他的test方法。
          使用invokespecial這種方式也有局限,只能從子類(lèi)調(diào)用。否則報(bào)錯(cuò):
          Exception in thread "main" java.lang.VerifyError: (class: Example, method: test1 signature: (LAI2;)V) Illegal use of nonvirtual function call
          posted @ 2012-05-31 11:23 yuxh 閱讀(2059) | 評(píng)論 (0)編輯 收藏
          使用Google calendar v3 API的時(shí)候,大量發(fā)現(xiàn)Builder使用。比如Credential類(lèi),查了查Builder模式的講解,始終感覺(jué)代碼的實(shí)現(xiàn)和標(biāo)準(zhǔn)定義不太相同。最后發(fā)現(xiàn)這種實(shí)現(xiàn)方式是《Effective java 2nd》中的一種實(shí)現(xiàn)(Item 2: Consider a builder when faced with many constructor parameters)。靜態(tài)工廠和構(gòu)造器都有一個(gè)通病:對(duì)于存在大量可選構(gòu)造參數(shù)的對(duì)象,擴(kuò)展性不好。經(jīng)典的解決方案是提供多個(gè)構(gòu)造函數(shù),第一個(gè)構(gòu)造函數(shù)只有必須的參數(shù),第二個(gè)構(gòu)造函數(shù)除了必須參數(shù)還有一個(gè)可選參數(shù),第三個(gè)除了必須參數(shù)還有兩個(gè)可選參數(shù)。。。這樣下去知道最后一個(gè)可選參數(shù)出現(xiàn)(telescoping constructor)。這種方案的問(wèn)題是,當(dāng)構(gòu)建對(duì)象的時(shí)候很容易把其中兩個(gè)參數(shù)的位置放反。。。。(難發(fā)現(xiàn)的bug)
          另一種解決方案是JavaBean 模式,先調(diào)用無(wú)參構(gòu)造函數(shù)再調(diào)用各個(gè)set方法來(lái)組裝對(duì)象。這種方案的問(wèn)題是不能強(qiáng)制一致性。如果沒(méi)有set某些必須的參數(shù)的話,對(duì)象可能處于不一致(
          inconsistent)的狀態(tài)(難發(fā)現(xiàn)的bug)。另外一個(gè)缺點(diǎn)是JavaBean模式不能讓類(lèi)immutable,需要程序員額外工作保證線程安全。
          第三種方式就是Builder設(shè)計(jì)模式。這種方式混合了telescoping constructor模式的安全性和JavaBean模式的可讀性。客戶端調(diào)用有所有必填參數(shù)的構(gòu)造器(或靜態(tài)工廠),得到一個(gè)builder對(duì)象。然后調(diào)用builder對(duì)象的方法去set各個(gè)選填參數(shù)。最后調(diào)用無(wú)參的build方法產(chǎn)生一個(gè)immutable的對(duì)象實(shí)例。immutable對(duì)象有非常多優(yōu)點(diǎn)而且可能很有用。builder的set方法都是返回builder本身,所以調(diào)用也是可以chained。如:
            GoogleCredential credentialNew = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
                              .setJsonFactory(JSON_FACTORY).setClientSecrets(clientSecrets)
                              .addRefreshListener(
          new CredentialStoreRefreshListener(userID, new DBCredentialStore())).build()
                              .setAccessToken(accessToken).setRefreshToken(refreshToken)
          客戶端代碼很好寫(xiě),更重要的是易讀。Builder模式模擬了在Ada和Python語(yǔ)言里的命名可選參數(shù)(named optional parameters)。
          同時(shí)Builder類(lèi)設(shè)置為static也是對(duì)Item 22:Favor static member classes over nonstatic的實(shí)踐
          posted @ 2012-05-30 17:44 yuxh 閱讀(398) | 評(píng)論 (0)編輯 收藏
          以典型的客戶端-服務(wù)器端授權(quán)為例
          一 基本流程
          使用Google Calendar v3 ,如果以servlet作為代理,可以使用官方示例,自己寫(xiě)一個(gè)類(lèi)A.java繼承AbstractAuthorizationCodeServlet類(lèi),這個(gè)類(lèi)主要用于跳轉(zhuǎn)到google提供的授權(quán)頁(yè)面,如果用戶同意授權(quán),則根據(jù)A類(lèi)中的URL(這個(gè)必須和注冊(cè)的google 回調(diào)路徑相同,比如oauth_callback否則報(bào)錯(cuò))重定向到B類(lèi),B.java 繼承AbstractAuthorizationCodeCallbackServlet類(lèi),這個(gè)訪問(wèn)路徑類(lèi)似http://www.example.com/oauth_callback?code=ABC1234。這里我配置oauth_callback為servlet的訪問(wèn)路徑,B類(lèi)中的
          onSuccess方法將根據(jù)獲得的access Token(這是根據(jù)傳過(guò)來(lái)的code獲得的)做業(yè)務(wù)操作。

          二 需要參數(shù)的情況
          有些業(yè)務(wù)需要用戶傳參數(shù),直接傳參數(shù)給A,再試圖在B中獲取是不行的!B類(lèi)中只能獲取某些固定的參數(shù),如code。要想傳用戶參數(shù),我們可以在A中先獲取,把幾個(gè)參數(shù)組裝為json格式字符串(還可以繼續(xù)base64編碼),把這個(gè)字符串作為state的值,再重定向到授權(quán)頁(yè)面,同意后state參數(shù)可以傳到B類(lèi),取值解析json字符串(或先base64解碼),得到參數(shù)。
          由于API中AuthorizationCodeRequestUrl有處理state的方法,而AbstractAuthorizationCodeServlet已經(jīng)直接封裝,為了使用setState,直接在A類(lèi)中繼承HttpServlet重寫(xiě)service方法,復(fù)制大部分AbstractAuthorizationCodeServlet的內(nèi)容,稍作修改:
          resp.sendRedirect(flow.newAuthorizationUrl().setState(json).setRedirectUri(redirectUri).build());

          三 關(guān)于refresh token
          默認(rèn)情況下,用戶授權(quán)之后token會(huì)有一個(gè)小時(shí)的有效期,之后你可以通過(guò)refresh token再重新獲取token。所以,如果不需要用戶再次授權(quán),可以在第一次,保存好token、refresh token、ExpirationTime。實(shí)例中用了JDO來(lái)實(shí)現(xiàn),自己如果使用數(shù)據(jù)庫(kù)保存,可類(lèi)似寫(xiě)一個(gè)類(lèi)實(shí)現(xiàn)CredentialStore類(lèi)。使用的時(shí)候,現(xiàn)在數(shù)據(jù)庫(kù)中取出,再創(chuàng)建credential,如:
                      GoogleCredential credentialNew = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
                              .setJsonFactory(JSON_FACTORY).setClientSecrets(clientSecrets)
                              .addRefreshListener(new CredentialStoreRefreshListener(userID, new DBCredentialStore())).build()
                              .setAccessToken(accessToken).setRefreshToken(refreshToken)
                              .setExpirationTimeMilliseconds(expirationTimeMilliseconds);
          在無(wú)效的情況下,Listener會(huì)自動(dòng)去用refresh token請(qǐng)求。
          posted @ 2012-05-08 11:40 yuxh 閱讀(954) | 評(píng)論 (0)編輯 收藏
          json格式經(jīng)常需要用到,google提供了一個(gè)處理json的項(xiàng)目:GSON,能很方便的處理轉(zhuǎn)換java對(duì)象和JSON表達(dá)。他不需要使用annotation,也不需要對(duì)象的源代碼就能使用。
          以字符串為例介紹:
          1 。構(gòu)造json 字符串
            例如要傳送json格式的字符串
                  String appID = req.getParameter("appID");
                  String userID  = req.getParameter("userID");
                  Map map = new HashMap();
                  map.put("appID", appID);
                  map.put("userID", userID);
                  Gson gson = new Gson();
                  String state = gson.toJson(map);
          2.解析json字符串
                    JsonParser jsonparer = new JsonParser();//初始化解析json格式的對(duì)象
                    String state = req.getParameter("state");
                    String appID = jsonparer.parse(state).getAsJsonObject().get("appID").getAsString();
                    String userID = jsonparer.parse(state).getAsJsonObject().get("userID").getAsString();
          posted @ 2012-05-08 10:23 yuxh 閱讀(2147) | 評(píng)論 (1)編輯 收藏
          通用協(xié)調(diào)時(shí)(UTC, Universal Time Coordinated),格林尼治平均時(shí)(GMT, Greenwich Mean Time) 由于歷史原因,這兩個(gè)時(shí)間是一樣的。
          北京時(shí)區(qū)是東八區(qū),領(lǐng)先UTC八個(gè)小時(shí),在電子郵件信頭的Date域記為+0800。
          轉(zhuǎn)換中,最重要的公式就是:
          UTC + 時(shí)區(qū)差 = 本地時(shí)間
              public static Calendar convertToGmt(Calendar cal) {
                  Date date 
          = cal.getTime();
                  TimeZone tz 
          = cal.getTimeZone();

                  System.out.println(
          "input calendar has date [" + date + "]");

                  
          // Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
                  long msFromEpochGmt = date.getTime();

                  
          // gives you the current offset in ms from GMT at the current date
                  int offsetFromUTC = tz.getOffset(msFromEpochGmt);
                  System.out.println(
          "offset is " + offsetFromUTC);

                  
          // create a new calendar in GMT timezone, set to this date and add the offset     
                  Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
                  Calendar utcCal 
          = Calendar.getInstance(TimeZone.getTimeZone("UTC"));

                  gmtCal.setTime(date);
                  //根據(jù)東西時(shí)區(qū),選擇offsetFromUTC為正或負(fù)數(shù)
                  gmtCal.add(Calendar.MILLISECOND, offsetFromUTC);

                  utcCal.setTime(date);
                  utcCal.add(Calendar.MILLISECOND, offsetFromUTC);

                  System.out.println(
          "Created GMT cal with date [" + gmtCal.getTime()
                          
          + "==" + utcCal.getTime() + "]");
                  
          return gmtCal;
              }
          posted @ 2012-03-15 23:08 yuxh 閱讀(1652) | 評(píng)論 (0)編輯 收藏
          Andriod 到3.2版本為止,webview方式下使用<input type="file" />點(diǎn)擊后都沒(méi)有反應(yīng)。實(shí)際上頂層是有隱含的接口沒(méi)實(shí)現(xiàn)的,可以自己重寫(xiě)這個(gè)方法來(lái)實(shí)現(xiàn)。以phonegap為例:

          public class App extends DroidGap {
              
          private ValueCallback<Uri> mUploadMessage;
              
          private final static int FILECHOOSER_RESULTCODE = 1;

              
          /** Called when the activity is first created. */
              @Override
              
          public void onCreate(Bundle savedInstanceState) {
                  
          super.onCreate(savedInstanceState);
                  
          super.init();
                  
          // WebView wv = new WebView(this);
                  
          // wv.setWebViewClient(new WebViewClient());
                  this.appView.setWebChromeClient(new CordovaChromeClient(App.this) {
                      
          // For Android 3.0+
                      public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
                          mUploadMessage 
          = uploadMsg;
                          Intent i 
          = new Intent(Intent.ACTION_GET_CONTENT);
                          i.addCategory(Intent.CATEGORY_OPENABLE);
                          i.setType(
          "image/*");
                          App.
          this.startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
                      }

                      
          // The undocumented magic method override
                      
          // Eclipse will swear at you if you try to put @Override here
                      public void openFileChooser(ValueCallback<Uri> uploadMsg) {
                          mUploadMessage 
          = uploadMsg;
                          Intent i 
          = new Intent(Intent.ACTION_GET_CONTENT);
                          i.addCategory(Intent.CATEGORY_OPENABLE);
                          i.setType(
          "image/*");
                          App.
          this.startActivityForResult(Intent.createChooser(i, "File Chooser"), App.FILECHOOSER_RESULTCODE);
                      }
                  });

                  
          // setContentView(wv);
                  super.loadUrl("file:///android_asset/www/login.html");
              }

              @Override
              
          protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
                  
          if (requestCode == FILECHOOSER_RESULTCODE) {
                      
          if (null == mUploadMessage)
                          
          return;
                      Uri result 
          = intent == null || resultCode != RESULT_OK ? null : intent.getData();
                      mUploadMessage.onReceiveValue(result);
                      mUploadMessage 
          = null;
                  }
              }
          }
          如果直接的webview方式,extends WebChromeClient即可。 參考:http://stackoverflow.com/questions/5907369/file-upload-in-webview
          posted @ 2012-03-12 12:54 yuxh 閱讀(5335) | 評(píng)論 (1)編輯 收藏
          weather.jsp:
          <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
          <%@ page import="java.io.*,java.net.*"%>
          <%
              StringBuffer sbf 
          = new StringBuffer();
              
          //Access the page
              try {
                
          //如果網(wǎng)絡(luò)設(shè)置了代理
                  System.setProperty("http.proxyHost""xxx");
                  System.setProperty(
          "http.proxyPort""80");
                  URL url 
          = new URL("http://www.google.com/ig/api?weather=london");
                  URLConnection urlConn 
          = url.openConnection();

                  BufferedReader in 
          = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
                  String inputLine;
                  
          while ((inputLine = in.readLine()) != null)
                      sbf.append(inputLine);
                  in.close();
                  System.out.println(
          "last="+sbf.toString());
              } 
          catch (MalformedURLException e) {
                  System.out.println(
          "MalformedURLException"+e);
              } 
          catch (IOException e) {
                  System.out.println(
          "IOException"+e);
              }
          %><%=sbf.toString()%>
          前臺(tái)js部分:

                  var childData   = function(selector, arg)
                  {
                          
          return selector.find(arg).attr('data');
                   }
                  $.ajax({
                      type : 
          "GET",
                      data : 
          "where=" ,
                      url : 
          "weather.jsp",
                      success : 
          function(data) {
                          console.debug('data
          ='+data);
                          forecast 
          = $(data).find('forecast_information');
                          cCondition 
          = $(data).find('current_conditions');

                          city 
          = childData(forecast, 'city');
                          
          if (city != undefined) {
                              date 
          = childData(forecast, 'forecast_date');

                              condition 
          = childData(cCondition, 'condition');
                              tempC 
          = childData(cCondition, 'temp_c');
                              humidity 
          = childData(cCondition, 'humidity');
                              icon 
          = childData(cCondition, 'icon');
                              $('#city').text(city);
                              $('#date').text(date);
                              $('#condition').text(condition);
                              $('#tempC').html(tempC 
          + '&deg; C');
                              $('#humidity').text(humidity);
                              $('#icon').attr({
                                  'src' : 'http:
          //www.google.com' + icon
                              });
                              $('#data').stop().show('fast');
                          } 
          else {
                              $('#error').stop().show('fast');
                          }
                      }
                  });
          posted @ 2012-02-22 08:58 yuxh 閱讀(239) | 評(píng)論 (0)編輯 收藏

          導(dǎo)航

          <2012年2月>
          2930311234
          567891011
          12131415161718
          19202122232425
          26272829123
          45678910

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆分類(lèi)

          隨筆檔案

          收藏夾

          博客

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 沙湾县| 达孜县| 紫金县| 长宁县| 濮阳市| 耒阳市| 徐闻县| 博湖县| 平果县| 灌云县| 六枝特区| 洞头县| 凤山县| 铁岭县| 鹤庆县| 张家川| 东港市| 鄯善县| 诏安县| 江安县| 台东市| 昌江| 湘西| 台中县| 泽普县| 樟树市| 邵武市| 武义县| 北票市| 定结县| 土默特左旗| 孟津县| 德阳市| 七台河市| 大同县| 江北区| 科技| 张家界市| 保亭| 高阳县| 安吉县|