第一步:先生成连接网站的快捷图标
第二步:写下载方法提供下载
代码如下:
1、生成快捷方式,然后把生成的快捷图标传到服务器上(注意:此方法安全级别低,所以我先生成连接网站的快捷图标,然后再写一个下载的方法让用户下载此快捷图标,你懂的...)
<html>
<head>
</head><body>
<script language="JavaScript">
function toDesktop(sUrl,sName){
try
{
var WshShell = new ActiveXObject("WScript.Shell");
var oUrlLink = WshShell.CreateShortcut(WshShell.SpecialFolders("Desktop") + "\\" + sName + ".lnk");
oUrlLink.TargetPath = sUrl;
oUrlLink.iconlocation="http://www.tj.10086.cn/1.ico"; //快捷图标
}
catch(e)
{
alert("当前IE安全级别不允许操作!");
}
}
</script>
<a href="#" onClick="toDesktop('http:\//www.tj.10086.cn/','天津移动')">生成快捷图标</a>
</body>
</html>
2、写下载快捷图标方法(前提是快捷图标已经生成并且已经传到服务器上)
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.net.URLEncoder" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<%
response.setContentType("application/x-download");//设置为下载application/x-download
String filedownload = "123.lnk";//即将下载的文件的相对路径
String filedisplay = "tj10086.lnk";//下载文件时显示的文件保存名称
filedisplay = URLEncoder.encode(filedisplay,"UTF-8");
response.addHeader("Content-Disposition","attachment;filename=" + filedisplay);
try
{
RequestDispatcher dis = request.getRequestDispatcher(filedownload);
if(dis!= null)
{
dis.forward(request,response);
}
response.flushBuffer();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
}
%>
<body>
</body>
</html>
到这里就完事了,祝你们快乐!