Primefaces UploadedFileName Turkish character issu

2019-09-03 15:58发布

I'm using PrimeFaces 5.1 and p:fileUpload component for uploading images. But I got undefined chrachters for Turkish chracters(for example "ı ç ş ğ"). I researched and tried a lot of wat but I couldn't succeed.I saw this question but not solved my problem. My char encoding filter like below. I also defined filter for this in web.xml file.

public class CharacterEncodingFilter implements Filter {

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
            req.setCharacterEncoding("ISO-8859-9");
            resp.setCharacterEncoding("ISO-8859-9");
            chain.doFilter(req, resp);
    }

    public void init(FilterConfig filterConfig) throws ServletException {

    }

    public void destroy() {

    }}

My handleFileUpload method

public void handleFileUpload(FileUploadEvent event) {
try {
System.out.println(new String(event.getFile().getFileName().getBytes("UTF-8")));
System.out.println(new String(event.getFile().getFileName().getBytes("ISO-8859-9")));
} catch (UnsupportedEncodingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

}

I'm getting this file names to UTF8 and ISO-8859-9 charsets for "Adsız.png".

Adsız.png

Adsız.png

2条回答
甜甜的少女心
2楼-- · 2019-09-03 16:37

Thank you @BalusC for your valuable comments. I changed to Tomcat encoding Cp1254 to UTF-8 and I confirm that I've used native PrimeFaces library and solved the problem. Thanks @BalusC again.

查看更多
祖国的老花朵
3楼-- · 2019-09-03 16:45

Can you checking this topic. try this code. Java Uploaded File Name

Web.xml

<filter>
    <filter-name>Character Encoding Filter</filter-name>
    <filter-class>org.primefaces.examples.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>Character Encoding Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
查看更多
登录 后发表回答