用jsp页面以流文件形式获取word文档显示全是乱码 怎么解决呀
<%@ 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>
这个怎么解决呀
------解决方案--------------------WORD的编码可不是UTF-8,你重新设置一下。
------解决方案--------------------http://blog.csdn.net/hellomc/article/details/4098302
你看看这个网页看看能否解决你的问题(@page contentType="application/msword;charset=utf8"%> 这种看一下这,还有下面的说的)
------解决方案--------------------你在开始的地方加上 request.setCharacterEncoding("UTF-8") 这句话试试
------解决方案-------------------- <meta http-equiv="pragma" content="no-cache" charset="utf-8">
试一下