是因为word里面包含有图片吧?试试把application/msword换成application/octet-stream;charset=gb2312试试看
没有附带图片的word,修改后还是有问题,多生成一个文件夹(立项申请表.files),文件夹中还有2个新文件:1、filelist.xml ; 2、header.htm
@68Q_Q68: 那把你怎么导的代码贴上来吧。
<%@ page language="java" pageEncoding="GBK"%>
<%
response.addHeader("Content-Type", "application/vnd.ms-word");
response.addHeader("Content-Type", "application/x-msword");
String fileName=request.getParameter("fileName")==null?"":request.getParameter("fileName");
if(fileName.equals("")){
fileName="word";
}
response.addHeader("Content-Disposition", "attachment; filename="+new String(fileName.getBytes(),"ISO-8859-1")+".doc");
response.addHeader("Expires", "0");
response.addHeader("Pragma", "cache");
response.addHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
String context = "<html xmlns:v=\"urn:schemas-microsoft-com:vml\" " +
"xmlns:o=\"urn:schemas-microsoft-com:office:office\" " +
"xmlns:w=\"urn:schemas-microsoft-com:office:word\" " +
"xmlns=\"http://www.w3.org/TR/REC-html40\"><style>" +
"body,tr,td{font-size:12px;} " +
".table_line{padding:3px;border-spacing: 0px;border:1px solid #c9caca; border-collapse:collapse;text-align:center;} " +
".table_line{width:100%;} " +
".tabel_head{background:#e7eef7;height:25px;text-align:center;border-right:1px solid #c9caca;} " +
".table_body{border-top:1px solid #c9caca;border-right:1px solid #c9caca;text-align:center;}</style>";
context += request.getParameter("sContent");
context = context.replaceAll("border=0", "border=1");
// context=context.replaceAll("FONT","img");
out.println(context);
%>
@68Q_Q68: 你把网页一起输出到客户端了,所以才会有那个文件夹出现了。java我不怎么会,我把它改成C#代码以后发现现象和你的差不多。我在最后一行加了句Response.End();以后就正常了。看下C#的代码:
Response.Clear();
Response.AddHeader("Content-Type", "application/vnd.ms-word");
Response.AddHeader("Content-Type", "application/x-msword");
//String fileName = Request.Params["fileName"] ?? "";
String fileName = "abc";
if (fileName.Equals(""))
{
fileName = "word";
}
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".doc");
Response.AddHeader("Expires", "0");
Response.AddHeader("Pragma", "cache");
Response.AddHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
String context = "<html xmlns:v=\"urn:schemas-microsoft-com:vml\" " +
"xmlns:o=\"urn:schemas-microsoft-com:office:office\" " +
"xmlns:w=\"urn:schemas-microsoft-com:office:word\" " +
"xmlns=\"http://www.w3.org/TR/REC-html40\"><style>" + "body,tr,td{font-size:12px;} " +
".table_line{padding:3px;border-spacing: 0px;border:1px solid #c9caca; border-collapse:collapse;text-align:center;} " +
".table_line{width:100%;} " +
".tabel_head{background:#e7eef7;height:25px;text-align:center;border-right:1px solid #c9caca;} " +
".table_body{border-top:1px solid #c9caca;border-right:1px solid #c9caca;text-align:center;}</style>";
//context += Request.Params["sContent"];
context += "aaaaaaa";
//context = context.Replace("border=0", "border=1");
Response.Write(context);
Response.End();
@LCM: 你看下jsp代码中out有没有close()方法或end()方法,加在后面试一下。out.close();
@LCM: out有个close方法,调用后还是不行。。并且调用后后台出现异常,不过文件还是能导出。