欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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();
	}

 

相关标签: servlet