String docname = new String(request.getParameter("name").getBytes("ISO-8859-1"),"gb2312");
File filePath=null; filePath = new File("/document");
if (!filePath.exists()) {
//输出syso
} BufferedInputStream br = new BufferedInputStream(new FileInputStream(filePath));
int byteLength = 10;
byte[] buf = new byte[byteLength];
int fLength = br.available();
int times = fLength/byteLength+1;
int mod = fLength%byteLength;
for(int i=1; i<=times; i++){
while(br.read(buf)!= -1){
if(i+1==times){
buf = new byte[mod];
}
}
}
int len = 0;
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename="+docname);
OutputStream out = response.getOutputStream();
while ((len = br.read(buf)) > 0)
out.write(buf, 0, len);
br.close();
out.close();
请大家帮忙看下 这个是可用的 只是 有些地方不知道哪写错了:
1.本地下载弹出来的时候 写的确实是文件名 但迅雷弹出来的是我下载所在的action名 这是为啥?
2.当我读取附件LIST在JS往页面动态写的时候 遇到附件名里有空格的时候 它就停止解析了 导致报错命令未正常结束 这个问 题咋整?希望大家帮帮忙 很急 小弟先在此谢过 祝大家 圣诞愉快!!!!
File filePath=null; filePath = new File("/document");
if (!filePath.exists()) {
//输出syso
} BufferedInputStream br = new BufferedInputStream(new FileInputStream(filePath));
int byteLength = 10;
byte[] buf = new byte[byteLength];
int fLength = br.available();
int times = fLength/byteLength+1;
int mod = fLength%byteLength;
for(int i=1; i<=times; i++){
while(br.read(buf)!= -1){
if(i+1==times){
buf = new byte[mod];
}
}
}
int len = 0;
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename="+docname);
OutputStream out = response.getOutputStream();
while ((len = br.read(buf)) > 0)
out.write(buf, 0, len);
br.close();
out.close();
请大家帮忙看下 这个是可用的 只是 有些地方不知道哪写错了:
1.本地下载弹出来的时候 写的确实是文件名 但迅雷弹出来的是我下载所在的action名 这是为啥?
2.当我读取附件LIST在JS往页面动态写的时候 遇到附件名里有空格的时候 它就停止解析了 导致报错命令未正常结束 这个问 题咋整?希望大家帮帮忙 很急 小弟先在此谢过 祝大家 圣诞愉快!!!!
解决方案 »
- request.getParameter()乱码处理问题
- 求助~Tomcat启动错误
- struts2 页面pojo 对set集合的操作
- struts 转化器问题
- 关于webservice发布到互联网上的问题!
- 我要怎样做,才能在我的eclipse里运行JSP文件呀!我的意思是说我已经配置好了tomcat,可是不知道怎么样才能运行?
- 大型IT企业的技术总监,需要什么样的能力素质?
- 【分享】Hibernate入门级项目全程实录完整版
- 我想请问一下这句话有什么错误?
- 怎么样完成这个功能,在C/S中很好实现的
- jsp+dao简单的增删查功能已经实现修改功能报java.sql.Date和java.util.Date转换异常
- 各位高手们,谁能帮我看看这个JSP作业啊,呜呜呜呜
response.setContentType("application/x-download");
String filedownload = application
.getRealPath("/download/tklfreesetup.exe");
String filedisplay = URLEncoder.encode("tklfreesetup.exe", "UTF-8");
response.addHeader("Content-Disposition", "attachment;filename="
+ filedisplay); java.io.OutputStream outp = null;
java.io.FileInputStream in = null;
try
{
outp = response.getOutputStream();
in = new FileInputStream(filedownload); byte[] b = new byte[1024];
int i = 0; while ((i = in.read(b)) > 0)
{
outp.write(b, 0, i);
}
//
outp.flush();
out.clear();
out = pageContext.pushBody();
}
catch (Exception e)
{
System.out.println("Error!");
e.printStackTrace();
}
finally
{
if (in != null)
{
in.close();
in = null;
}
}