用jsp页面以流文件形式获取word文档显示全是乱码 怎么解决呀

jinhu0618 2012-05-30 11:44:12
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.io.*" %>
<%
String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
</head>

<body>

<%
File file = null;
FileInputStream fis = null;
try{
String filePath = application.getRealPath("/").replace("\\","/") + "file/readme.doc";
file = new File(filePath);
fis = new FileInputStream(file);
byte[] buffer = new byte[1024];
while(-1 != (fis.read(buffer,0,buffer.length))){

String str = new String(buffer,"UTF-8");
out.print(str);
}
}
catch(Exception ex){

ex.printStackTrace();
}
finally{
if(fis != null){
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

%>
</body>
</html>

这个怎么解决呀
...全文
279 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jinhu0618 2012-05-30
  • 打赏
  • 举报
回复
把编码换成gb2312 也不可以呀
  • 打赏
  • 举报
回复
WORD的编码可不是UTF-8,你重新设置一下。
jackson_fighting 2012-05-30
  • 打赏
  • 举报
回复
<meta http-equiv="pragma" content="no-cache" charset="utf-8">

试一下
太阳峰 2012-05-30
  • 打赏
  • 举报
回复
你在开始的地方加上 request.setCharacterEncoding("UTF-8") 这句话试试
qiaozizhen123 2012-05-30
  • 打赏
  • 举报
回复
http://blog.csdn.net/hellomc/article/details/4098302
你看看这个网页看看能否解决你的问题(@page contentType="application/msword;charset=utf8"%> 这种看一下这,还有下面的说的)

81,122

社区成员

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

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