久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      java下載文件中文文件名亂碼

      java下載文件中文文件名亂碼

      問題引出:

      上傳中文命名的圖片,下載顯示不了中文名稱。

      如圖:

      java下載文件中文文件名亂碼

      (相關視頻教程推薦:java視頻教程)

      解決方法:

      1、sping-mvc.xml部分代碼:

      	<!-- 上傳文件的處理器 --> 	<bean id="multipartResolver" 		class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 		<!-- 設置默認編碼 解決了上傳文件名亂碼的問題 --> 		<property name="defaultEncoding" value="utf-8"></property> 		<!-- 上傳圖片最大大小5M --> 		<property name="maxUploadSize" value="5242440"></property> 	</bean>

      2、FileController.java中文文件名獲取代碼:

      獲取瀏覽器格式,根據(jù)不同瀏覽器控制文件名編碼格式。

      String userAgent = request.getHeader("User-Agent");//獲取瀏覽器名(IE/Chome/firefox) if(userAgent.contains("MSIE")||userAgent.contains("Trident")) {//針對IE或IE為內(nèi)核的瀏覽器 	fileName=java.net.URLEncoder.encode(fileName,"UTF-8"); 	}else { 		fileName=new String(fileName.getBytes("UTF-8"),"ISO-8859-1");//谷歌控制版本 } headers.setContentDispositionFormData("attachment", fileName);// 默認下載文件名為原始文件名

      其他瀏覽器控制字符格式:(詳細)

      String userAgent = request.getHeader("User-Agent");//獲取瀏覽器名(IE/Chome/firefox) if (userAgent.contains("firefox")) {           fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1"); // firefox瀏覽器         } else if (userAgent.contains("MSIE")) {          fileName = URLEncoder.encode(fileName, "UTF-8");// IE瀏覽器         }else if (userAgent.contains("CHROME")) {          fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");// 谷歌       }   headers.setContentDispositionFormData("attachment", fileName);// 默認下載文件名為原始文件名

      相關文章教程推薦:java入門教程

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號