簡體   English   中英

使用質數上傳文件時出現編碼問題

[英]Encoding issue while uploading file with primefaces

我和這里有同樣的問題。

我使用primefaces 2.2 jsf實現。 我嘗試了所有方法,但沒有任何效果。 還有其他解決方案嗎? 當我嘗試new String (s.getBytes ("iso-8859-1"), "UTF-8"); ,我怎么知道輸入編碼?

String fileName=new String(event.getFile()
                                 .getFileName()
                                 .getBytes(Charset.defaultCharset()),"UTF-8").toUpperCase(locale);

輸入編碼就是服務器用作默認編碼而不是UTF-8的任何內容。 因此,這是一個應用程序范圍的設置,因此不依賴於特定的HTTP請求/客戶端。 更常見的是,它與Charset#defaultCharset()

對於具體問題,請注意,PrimeFaces 3.3當前仍在為此苦苦掙扎。 另請參閱帶有utf8字符過濾器的primefaces fileupload過濾器 ,您可以在其中找到一些提示,這些內容只是用於破解PrimeFaces源代碼本身以修復該錯誤。

在開發日語網站時,我也會遇到此類問題。 文本變成未知字符。 經過一番谷歌搜索,我能夠解決這個問題。 這是我的解決方案。

<h:form enctype="multipart/form-data;charset=UTF-8">
  <p:fileUpload id="image" immediate="true" auto="true" sizeLimit="1048576" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" fileUploadListener="#{uploadController.uploadListener}" mode="advanced" multiple="true"/>
</h:form>

您只需要在multipart/form-data;charset=UTF-8的enctype中添加multipart/form-data;charset=UTF-8

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM