jsp下载文件时出现乱码???????????

provider 2004-07-02 05:21:56
使用jsp写了一个下载文件小程序,在运行时打开的word文挡为乱码,什么原因,大家知道吗?
代码如下:
<%@ page import="java.io.*" %>
<%@ page import="useraction.*" %>
<%@ page contentType="charset=gb2312"%>
<%

///////////////////////////////
PrintWriter printwriter = response.getWriter();
String s = request.getParameter("file");
String s1 = request.getParameter("filename");
System.out.println("文件路径:"+s);
System.out.println("文件名::"+s1);
response.setContentType("appliction/msword");
response.setHeader("Content-Disposition", "attachment; filename=" + s1 + "");
FileInputStream fileinputstream = new FileInputStream(s);
FileOutputStream fileoutputstream = new FileOutputStream("d:\\a.doc");
int i;
while((i = fileinputstream.read()) != -1)
{
printwriter.write(i);
fileoutputstream.write(i);
}
fileinputstream.close();
fileoutputstream.close();
printwriter.close();
printwriter.println("<body onload=window.close()>");


%>
...全文
157 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
gjd111686 2004-07-02
  • 打赏
  • 举报
回复
这个应该是读取问题[Word在字节数不对的情况下为乱码.]

如果是链接中文可以用URLEncoder.encode
shiyonggang 2004-07-02
  • 打赏
  • 举报
回复
没碰到过,但还是帮你up
provider 2004-07-02
  • 打赏
  • 举报
回复
其中输出的文件"a.doc"打开为中文,在浏览器中输出的为乱码,不知道是不是需要一些特殊的设置。



注:后台的app server: weblogic

81,120

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧