首页 / 操作系统 / Linux / 遇到的Struts2文件下载乱码问题
今天用struts2写文件的下载,出现了文件名为中文时有乱码的问题。参考了很多网上和书上的方法但是不奏效。以下是我的解决方法,虽然很简单直白,但是解决问题了,供大家参考。public String getDownFileName() throws UnsupportedEncodingException { return java.net.URLDecoder.decode(downFileName, "utf-8"); } public void setDownFileName(String downFileName) throws UnsupportedEncodingException {// this.downFileName = new String(downFileName.getBytes("utf-8"),"iso-8859-1"); this.downFileName = java.net.URLEncoder.encode(downFileName, "utf-8"); }其实就是先进行utf-8编码,然后再utf-8解码。我理解是因为服务器端和客户端的编码方式不一样,所有要进行统一的编码Struts 的详细介绍:请点这里
Struts 的下载地址:请点这里推荐阅读:Struts中异步传送XML和JSON类型的数据 http://www.linuxidc.com/Linux/2013-08/88247.htmStruts2的入门实例 http://www.linuxidc.com/Linux/2013-05/84618.htm