问题
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
回答1:
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.
回答2:
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>
来源:https://stackoverflow.com/questions/29261473/primefaces-uploadedfilename-turkish-character-issue