JSP禁用迅雷等下载工具下载文件,强制使用右键另存功能下载文件
* 实现文件另存功能*
* @param text
* 文件内容
* @param fileName
* 文件名称
* @return
*/
protected String renderFile(String text, String fileName)
throws IOException
{
response.addHeader("Content-Disposition", "attachment; filename="
+ fileName);
response.setContentType("application/octet-stream");
response.setCharacterEncoding("GB2312");
response.getWriter().write(text);
response.flushBuffer();
response.getWriter().close();
return null;
}
下载的action:
/** *//**
* 提供下载的方法
* @return
*/
public String down()
{
String dir = getFullPath() + "/upload/file/";
try
{
if (!FileUtils.exists(dir))
{
new File(dir).mkdirs();
}
Random r = new Random(System.currentTimeMillis());
Integer randomInt = r.nextInt();
this.renderFile("test content:" + randomInt,randomInt + ".txt");
}
catch (IOException e)
{
e.printStackTrace();
this.renderText(e.getMessage());
}
return null;
}
页面链接调用:
<a href="${ctx}/va/va!down.do" >下载</a>
感激涕零,谢谢楼主的好贴
static/image/common/sigline.gif
http://img2081.poco.cn/mypoco/myphoto/20110822/16/64165363201108221627279573116820626_005.jpg 好多啊,哈哈,谢谢您
static/image/common/sigline.gif
敦煌热血传奇家族 费县冒险岛sf下载 贞丰魔域私服 望谟热血江湖新闻 蒙城魔力宝贝私服 化州传奇私服网站 青冈魔兽GM 罗定奇迹私服
玉田惊天动地论坛 闽清诛仙sf 要顶的啊,楼主辛苦了,谢谢
static/image/common/sigline.gif
西吉最炫网页游戏 绵竹微变传奇私服 淮北蜀门sf网站 鄂托克旗永恒之塔论坛 西乌珠穆沁旗神魔大陆发布网
页:
[1]