分享

java,javascript 内连取数据

 pengx 2008-06-25
java 内连
            //用 java jdk URL
            URL httpurl 
= new
 URL(url);
            HttpURLConnection httpConn 
= null
;
            httpConn 
=
 (HttpURLConnection) httpurl.openConnection();
            httpConn.setRequestMethod(
"POST"
);
            httpConn.setDoOutput(
true
);
            httpConn.setDoInput(
true
);
            //
正式连接
            httpConn.getOutputStream();
            
byte[] bb = new byte
[httpConn.getInputStream().available()];
            httpConn.getInputStream().read(bb);
            //取得数据
            String str 
= new String(bb);

javascript 现在这种取法有个名字叫(ajax)(转)

<html>
<head>
<link href="http://www./css/index.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="http://www./css/framework.css" type="text/css"/>
 
<script language="javascript">
 
 window.onload 
= function()
 {
  CreateDateSelect();
 }

 
var xmlHttp = false
;
 
var
 e;
 
 
//创建XMLHTTP对象

 function getXMLHTTPObj()
 {
  
var C = null
;
  
try

  {
     C 
= new ActiveXObject("Msxml2.XMLHTTP");
  }
  
catch
(e)
  {
   
try

   {
    C 
= new ActiveXObject("Microsoft.XMLHTTP");
   }
   
catch
(sc)
   {
    C 
= null
;
   }
  }
  
  
if!&& typeof XMLHttpRequest != "undefined"
 )
  {
   C 
= new
 XMLHttpRequest();
  }
  
  
return
 C;
 }
 
 
//调用远程方法

 function callServer(e)
 { 
  
try

  {
   
if( xmlHttp && xmlHttp .readyState != 0 )
   {
    xmlHttp.abort();
   }
   
   xmlHttp 
=
 getXMLHTTPObj();
   
   
if
( xmlHttp )
   {
    document.getElementById(
"outgroup").style.display = "none"
;
    
//获取查询日期

    var dateSele = e.options[e.selectedIndex].value;
    document.getElementById(
"date").innerHTML = dateSele + " 开放式基金净值"
;

    
//构造查询连接字符串

    var url = "https://www.google.com/accounts/ManageAccount";
    
    
//打开连接

   if(navigator.appName == ‘Netscape‘){
   
try
 {
    netscape.security.PrivilegeManager.enablePrivilege(
"UniversalBrowserRead"
);
   } 
catch
 (e) {
       alert(
"Permission UniversalBrowserRead denied."
);
   }}
    xmlHttp.open(
"GET", url, true
);
    
//设置回调函数

    xmlHttp.onreadystatechange = updatePage;
    
//发送请求

    xmlHttp.send(null);
   }
   
else

   {
    document.getElementById(
"flag").innerHTML = "XMLHTTP对象创建失败";
   }
  }
  
catch
 (e)
  {
   document.getElementById(
"flag").innerHTML = "查询错误:" +
 e;
  }
 }
 
 
//回调处理函数

 function updatePage()
 {
  
try
 {
   
if (xmlHttp.readyState == 1
)
   {
    document.getElementById(
"flag").innerHTML = "正在加载连接对象"
;
   }

   
if (xmlHttp.readyState == 2
)
   {
    document.getElementById(
"flag").innerHTML = "连接对象加载完毕。"
;
   }

   
if (xmlHttp.readyState == 3
)
   {
    document.getElementById(
"flag").innerHTML = "数据获取中"
;
   }

   
if (xmlHttp.readyState == 4
)
   {
    
var response =
 xmlHttp.responseText;
    document.getElementById(
"out").innerHTML =
 response;
    document.getElementById(
"outgroup").style.display = ""
;
   }
  }
  
catch
 (e)
  {
      document.getElementById(
"flag").innerHTML = "回调处理错误:" +
 e;
  }
 }

 
//创建日期选择下拉框

 function CreateDateSelect()
 {

  
var html =
 [];
         
  
for(var iYear=2005; iYear<=2006; iYear ++
)
  {
   
forvar iMonth=1; iMonth<=12; iMonth ++
 )
   {
    
forvar iDay=1; iDay<=31; iDay ++
 )
    { 
    html[html.length] 
= "<option value=\""  + iYear + "\-" + iMonth + "\-" + iDay + "\">" + iYear + "" + iMonth + "" + iDay + "" + "</option>"
;
    }
   }
  }
      
  document.getElementById(
"dateSele").innerHTML = "<select name=\"dateSele\" id=\"dateSele\" onchange=\"callServer(this);\">" + html.join(""+ "</select>"
;
 } 
 
</script>

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多