public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("UTF-8");
String str = request.getParameter("hhstr");
String filename = "cist";//默认下载文件名
String tfile= request.getParameter("filename");
if(tfile != null && !"".equals(tfile.trim())){
tfile = URLDecoder.decode(tfile.trim(), "UTF-8");
tfile=new String(tfile.getBytes("ISO8859-1"),"UTF-8");
filename = tfile;
}
if(str != null && !"".equals(str.trim())){
str = URLDecoder.decode(str.trim(), "UTF-8");
str=new String(str.getBytes("ISO8859-1"),"UTF-8");
}
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setHeader("Content-disposition",
"attachment; filename="+filename+".xls");
ServletOutputStream out = response.getOutputStream();
if(str != null)out.write(str.getBytes());
out.flush();
out.close();
}
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("UTF-8");
String str = request.getParameter("hhstr");
String filename = "cist";//默认下载文件名
String tfile= request.getParameter("filename");
if(tfile != null && !"".equals(tfile.trim())){
tfile = URLDecoder.decode(tfile.trim(), "UTF-8");
tfile=new String(tfile.getBytes("ISO8859-1"),"UTF-8");
filename = tfile;
}
if(str != null && !"".equals(str.trim())){
str = URLDecoder.decode(str.trim(), "UTF-8");
str=new String(str.getBytes("ISO8859-1"),"UTF-8");
}
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setHeader("Content-disposition",
"attachment; filename="+filename+".xls");
ServletOutputStream out = response.getOutputStream();
if(str != null)out.write(str.getBytes());
out.flush();
out.close();
}
fileName = URLEncoder.encode(fileName, "utf-8");
fileName = fileName.replace('+', ' ');
servletResponse.setContentType("application/x-download");
servletResponse.addHeader("Content-Disposition",
"attachment;filename=" + fileName);
str=new String(str.getBytes("ISO8859-1"),"UTF-8");
以上2行直接删了吧。