1、第一种情况下载时如果文件名存在中文则需要进行编码
String downloadFileName = new String (filename.getBytes("UTF-8"),"ISO-8859-1");
2、第二种情况当文件名是从之前的表单提交上来的时候,jsp页面传过来的文件名存在中文的话,如果没设置spring过滤的话会出现中文乱码,需要在web.xml添加以下代码:
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>