jsp,java在桌面生成网站快捷方式

3 篇文章 0 订阅
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.io.*"%>
<%@page import="javax.swing.filechooser.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%
	String templateContent = "[InternetShortcut]" + "\n" + "URL= http://www.baidu.com";   
	String realfilename = "百度" + ".url";   
	FileSystemView fsv = FileSystemView.getFileSystemView();    
	String upurl = fsv.getHomeDirectory().toString();   
	System.out.println(upurl);   
	String filename = upurl + "/" + realfilename;   
	File myfile = new File(filename);   
	if(!myfile.exists()){
	    FileOutputStream fileoutputstream = new FileOutputStream(filename);//建立文件输出流    
	    byte tag_bytes[] = templateContent.getBytes();   
	    fileoutputstream.write(tag_bytes);   
	    fileoutputstream.close();   
	}
	try {   
	    File file = new File(upurl, realfilename);   
	    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));   
	    byte[] buffer = new byte[111000];   
	    realfilename = java.net.URLEncoder.encode(realfilename,   
	    "UTF-8");   
	    response.reset();   
	    response.setCharacterEncoding("UTF-8");   
	    response.setContentType("application/x-download");//不同类型的文件对应不同的MIME类型   
	    response.setHeader("Content-Disposition",   
	    "attachment; filename=" + realfilename);   
	    OutputStream os = response.getOutputStream();   
	    while (bis.read(buffer) > 0) {   
	        os.write(buffer);   
	    }   
	    bis.close();   
	    os.close();   
	    out.clear();   
	    out=pageContext.pushBody();   
	} catch (Exception e) {   
	    e.printStackTrace();   
	} 

%>

</body>
</html>


只要访问本页面就可以自动在桌面创建快捷方式,当然,其他路径也可以。如果想点击按钮生成快捷方式,把按钮的链接设置成本页面即可!

评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值