日期:2014-05-16  浏览次数:20358 次

jsp端自动下载并保存图片文件
JScript code
<script language="javascript" type="text/javascript">
//js自动下载文件到本地
var xh;
function getXML(geturl)
{
    //alert("ll");
    xh = new ActiveXObject("Microsoft.XMLHTTP");
    xh.onreadystatechange = getReady;
    xh.open("GET",geturl,true);                   
    xh.send();                        
}

function getReady()
{
    alert(xh.readyState);
    if(xh.readyState==4)
    {
        if(xh.status==200){
            saveFile("d:\mm.exe");
            return true;
        }
        else
        {return false;}
    }
    else
        return false;
}

function saveFile(tofile)
{
    var objStream;
    var imgs;
    imgs = xh.responseBody;
    objStream = new ActiveXObject("ADODB.Stream");
    objStream.Type = 1;
    objStream.open();
    objStream.write(imgs);
    objStream.SaveToFile(tofile)
}
getXML("http://192.168.22.206/servlet");

</script>