JSP文件下载,文件名中文乱码问题解决方案.
程序员文章站
2022-03-19 17:40:44
...
目前尚未处理文件中有中文的情况.
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
// response.setContentType("text/html");
// response.setHeader("Content-disposition","attachment;filename="+"你.doc");
//通知客户要下载文件类型
// response.setContentType("application/msword");
response.setContentType("application/octet-stream;charset=UTF-8");
String filename2=new String("测试.doc".getBytes("utf-8"),"iso-8859-1");
response.setHeader("Content-disposition","attachment;filename="+ filename2 + "");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
上一篇: 精准灵活的微博推广 高质量内容时效性高
下一篇: 关于小红书推广的5点分析与建议