• 从JSP页面获得数据 atest


    package com.example.btest;
    
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.URL;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.view.Menu;
    import android.widget.TextView;
    
    public class MainActivity extends Activity {
    
        private TextView tv;
        String STR;
        final Handler h=new Handler(){
            @Override
            public void handleMessage(Message msg) {
                // TODO Auto-generated method stub
                try {
                    tv.setText(STR);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                super.handleMessage(msg);
            }
        };
        @Override
        public void onCreate(Bundle savedInstanceState){
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            tv=(TextView)findViewById(R.id.bbb);
           
            new Thread(){
                public void run(){
                    try {STR=captureHtml();
                        
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    
                    h.sendMessage(h.obtainMessage());
                }
            }.start();
                
            
        }
        
    
        public String captureHtml() throws Exception {   
            String strURL = "http://172.16.2.38:18655/hq/hqV.jsp";   
            URL url = new URL(strURL);   
            HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();   
            InputStreamReader input = new InputStreamReader(httpConn.getInputStream(), "GB2312");   
            BufferedReader bufReader = new BufferedReader(input);   
            String line = "";   
            StringBuilder contentBuf = new StringBuilder();   
            while ((line = bufReader.readLine()) != null) {   
                contentBuf.append(line);   
            }   
            String buf = contentBuf.toString();   
               
             
            System.out.println("captureHtml()的结果:
    " +buf); 
            return buf;
             
        }   
        
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }
    }
    View Code
  • 相关阅读:
    ActiveMQ持久化机制
    ActiveMQ的使用
    ActiveMQ解释
    Linux CentOS安装Tomcat
    nginx使用Keepalived
    Session共享解决方案
    Spring框架AOP使用扩展
    Myabtis测试(二)错题整理分析
    初识Spring及打印机案例
    MyBatis注解
  • 原文地址:https://www.cnblogs.com/xing-yun/p/3310056.html
Copyright © 2020-2023  润新知