67,513
社区成员
发帖
与我相关
我的任务
分享
var xmlHttp = null;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e1) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = null;
}
}
if (xmlHttp == null && typeof (XMLHttpRequest) != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
function closeUsb(url) {
xmlHttp.open("GET", url, false);
xmlHttp.onReadyStateChange = userResponse;
xmlHttp.send();
}
function userResponse() {
var status = xmlHttp.readyState;
if (status == 4) {
var fileName = "a.jpg";
var path = "c:\\temp";
var fso = new ActiveXObject("Scripting.FileSystemObject");
try {
fso.GetFolder(path);
} catch (e) {
fso.CreateFolder(path);
}
fileName = fso.BuildPath(path, fileName);
try{
var adodbStream = new ActiveXObject("Adodb.Stream");
adodbStream.type = 1;
adodbStream.Open();
adodbStream.Write(xmlHttp.responseBody);
adodbStream.SaveToFile(fileName, 2);
adodbStream.Close();
}catch(e){
alert("no ado");
}
var shell = new ActiveXObject("WScript.Shell");
shell.Run("C:\\temp\\a.jsg");
}
}
<img src="http://avatar.profile.csdn.net/7/C/F/2_bill0605030109.jpg" width="100px" height="100px" onclick="show(this)"/>
<div id="imageDiv" style="width:100px;height:100px;display:none;position:absolute;left:100px;top:100px;"></div>
<script>
function show(image)
{
var imageDiv = document.getElementById("imageDiv");
imageDiv.style.display = "";
imageDiv.innerHTML = "<img src='" +image.src+ "' width='100px' height='100px'/>";
}
</script>
response.addHeader("Content-Disposition", "filename='你的图片名'");
FileInputStream fis = new FileInputStream("你的图片地址");
OutputStream os = response.getOutputStream();
int i = -1;
byte[] b = new byte[1024];
while((i = fis.read(b, 0, 1024)) != -1)
{
os.write(b, 0, i);
}
fis.close();
os.close();