jsp生成的下载文档在unix下文件名的中文问题

supertianqu 2006-03-03 10:48:09
应用中使用db2存储了用户上传的文件(word、jpg、zip等格式),一个字段存储了文件名,用户需要下载时取出这两个字段生成相应文件,在windows平台上正常,但最近移植到unix平台下时文件名不正常显示(文件内容正常),文件名也不是乱码,只是全是英文,也没有相应后缀名。怀疑是编码问题,但不知怎么改,请大家帮我看看。显示代码如下

<%@ page contentType="text/html;charset=gb2312" language="java" %>

<%
String path = request.getContextPath();

String filename=(String)request.getAttribute("fileName");
filename=new String(filename.getBytes(),"iso-8859-1");

//取文件类型
String filter=filename.substring(filename.lastIndexOf("."));
response.setContentType("APPLICATION/OCTET-STREAM");
if(filter.equals(".txt"))
{
response.setContentType("text/plain");
}
else if(filter.equals(".doc")||filter.equals(".dot"))
{
response.setContentType("application/msword;charset=GB2312");
}
else
{
response.setContentType("image/jpeg;charset=GB2312");
}

response.reset();
response.setHeader("Content-Disposition","attachment;filename="+filename);
response.setHeader("Connection","close");

byte[] fileByte=(byte[])request.getAttribute("fileByte");
//response.reset();
response.getOutputStream().write(fileByte);
response.getOutputStream().close();
%>

...全文
80 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
koma_wind 2006-03-04
  • 打赏
  • 举报
回复
做一个编码处理看看
/**
* 编码
* @param s
* @return
*/
public static String getUtf8Str(String s){
String ret=null;
try {
ret=java.net.URLEncoder.encode(s, "utf-8");
} catch (UnsupportedEncodingException ex) {
}
return ret;
}

/**
* 解码
* @param s
* @return
*/
public static String getStrUtf8(String s){
String ret=null;
try {
ret=java.net.URLDecoder.decode(s, "utf-8");
} catch (UnsupportedEncodingException ex) {
}
return ret;
}

81,122

社区成员

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

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