• JAVA中获取远程页面内容 和 xmlhttp远程处理


    //BY ZGJ:获取远程页面内容
     public static String GetPageContent(String pageURL)
     {
      String pageContent="";
      BufferedReader in = null;
         InputStreamReader isr = null;
         InputStream is = null;
         PrintWriter pw=null;
         HttpURLConnection huc = null;
         try
         {
            URL url = new URL(pageURL);
            //创建 URL
            huc = (HttpURLConnection)url.openConnection();
            is = huc.getInputStream();
            isr = new InputStreamReader(is);
            in = new BufferedReader(isr);
            String line = null;
            while(((line = in.readLine()) != null))
            {
               if(line.length()==0)
                   continue;
               pageContent+=line;
             }   
          }
          catch (Exception e)
          {
                 System.err.println(e);
           }
           finally
           {  //无论如何都要关闭流
                 try
                 {is.close(); isr.close();in.close();huc.disconnect();pw.close();   
                 }
                 catch (Exception e) {}
          }
       return pageContent;
     }

    xmlhttp远程处理

    function Upload()
    {
     var agt = navigator.userAgent.toLowerCase();
        var is_ie = (agt.indexOf('msie') != -1);
        var is_ie5 = (agt.indexOf('msie 5') != -1);
     function handle_do_search ()
     {
      if (xmlhttp.readyState == 4)//request completed
      {
       if (xmlhttp.status == 200)//request successful
       {
        var responseText = xmlhttp.responseText;
        if(responseText.indexOf("ok")==-1)
        {
         alert("上传出错,请查看错误信息!");
         document.getElementById("errInfo").innerText="错误信息:"+responseText;
        }
        else
        {
         alert("上传成功!");
         if("<%=fileCreate%>"=="")
          document.getElementById('xmlFrame').src="<%=request.getContextPath()%>"+"/out/UpDownData.xml";
        }
       }
       else
       {
        alert ("中心服务器无应答!");
       }
      }
     }
     var xmlhttp = null;
     if (is_ie)
     {
      var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
      try
      {
       xmlhttp = new ActiveXObject(control);
       xmlhttp.onreadystatechange = handle_do_search;
      } catch(e)
      {
       alert("请允许ActiveX controls执行!");
      }
     }
     else
     {
      xmlhttp = new XMLHttpRequest();
      xmlhttp.onload = handle_do_search;
      xmlhttp.onerror = handle_do_search;
     }
     xmlhttp.open("POST",uploadURL, false);
     xmlhttp.send(contentXML);
    }

    远程接收XMLHTTP处理:

    request.setCharacterEncoding("UTF-8");
       BufferedReader in = request.getReader();
       String line="";
       String contentXML = "";
       while ((line = in.readLine()) != null)
       {
       //构造数据包
       contentXML = contentXML+line;
       }
       if(!contentXML.equals(""))
        resultMsg=JSPUtil.InsertData(contentXML);
       if(resultMsg.equals(""))
           out.println("ok");
          else
           out.println(resultMsg);

  • 相关阅读:
    简析IGRP
    unicode字符集查找
    中国移动建成全球最大软交换网络 适合向3G过渡
    寻找端口与进程的关联
    framerelay
    网络工程师的素质
    E1通信的基础知识
    Indy UDP端口冲突解决
    『软考』接入网的分类
    随便写写。。
  • 原文地址:https://www.cnblogs.com/willpower/p/1258174.html
Copyright © 2020-2023  润新知