Uploaded filename encoding issue for Japanese and Chinese

后端 未结 1 1205
暖寄归人
暖寄归人 2021-02-09 02:40

I am currently using the jQuery-File-Upload. I may upload some files with a Japanese or Chinese file name, and I can see that the file name is for example, \"お疲れ様です.txt\" or \"测

1条回答
  •  情书的邮戳
    2021-02-09 03:16

    As Stephen C said a filter can be used to get the right encoding. We had this problem on JBOSS 7.1.1 and implemented a filter.

    In web xml

    
        set character encoding
        RequestEncodingFilter
        com.myapp.RequestEncodingFilter
        
            encoding
            UTF-8
        
    
    
        RequestEncodingFilter
        /*
    
    

    Filter class:

    public class RequestEncodingFilter implements Filter {
    
    private static final String ENCODING = "encoding";
    private String configuredEncoding;
    
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        configuredEncoding = filterConfig.getInitParameter(ENCODING);
    }
    
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding(configuredEncoding);
        filterChain.doFilter(servletRequest, servletResponse);
    }
    
    @Override
    public void destroy() {
    }
    

    }

    0 讨论(0)
提交回复
热议问题