Characters “ي” and “ی” and the difference in persian - Mysql

前端 未结 8 1187
忘掉有多难
忘掉有多难 2020-12-23 19:56

I\'m working on a UTF-8 Persian website with integrated mysql database. All the content in the website are imported through an admin panel and it\'s all persian.

As

8条回答
  •  不思量自难忘°
    2020-12-23 20:15

    I know answering this topic is like digging a corpse from its grave since it's really old but I'd like to share my experience IMHO, the best way is to wrap your request and apply your replacement . it's more portable than other ways. here is a java sample

    public class FarsiRequestWrapper extends HttpServletRequestWrapper{
    
    @Override
    public String getParameter(String name) {
        String parameterValue = super.getParameter(name);
        parameterValue.replace("ی", "ي");       
        parameterValue.replace("\\s+", " ");
        parameterValue.replace("ک","ک");
        return parameter.trim();
    }
    

    }

    then you only need to setup a filter servlet

    public class FarsiFilter implements Filter{
    
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
    
        HttpServletRequest req = (HttpServletRequest) request;
        FarsiRequestWrapper rw = new FarsiRequestWrapper(req);
        chain.doFilter(rw, response);
    }
    

    } although this approach only works in Java, I found it simpler and better.

提交回复
热议问题