Posted on 2008-01-09 09:46
G_G 阅读(1156)
评论(0) 编辑 收藏 所属分类:
javascript 、
javaGeneral
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();
/**输入参数
PrintWriter outs = new PrintWriter(httpConn.getOutputStream());
outs.print("&back_url=" + returnurl);
outs.print("&orderid=" + deposit.getOrderId());
outs.print("&bussinessid=" + SZFConstant.B_ID);
outs.print("&digestString="
+ MD5Util.MD5Encode(SZFConstant.B_ID + deposit.getOrderId()
+ SZFConstant.KEY));
outs.flush();
outs.close();
GET 就不要 说 了 url + 参数
*/
byte[] bb = new byte[httpConn.getInputStream().available()];
httpConn.getInputStream().read(bb);
//取得数据
String str = new String(bb);
javascript 现在这种取法有个名字叫(ajax)(转)
<html>
<head>
<link href="http://www.cc168.com.cn/css/index.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="http://www.cc168.com.cn/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( !C && 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 ++)
{
for( var iMonth=1; iMonth<=12; iMonth ++ )
{
for( var 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>