【问题标题】:Turkish characters could not be displayed in website. Tomcat Server, Mysql Database土耳其语字符无法在网站中显示。 Tomcat 服务器,Mysql 数据库
【发布时间】:2016-04-22 20:43:42
【问题描述】:

土耳其语字符显示为“?”并错误地插入了数据库。 我可以更改 phpmyadmin 中的文本并再次使其成为土耳其语。通过这种方式,一切都很完美。

我的编码过滤器:

private String encoding;

public void init(FilterConfig config) throws ServletException {
    encoding = config.getInitParameter("requestEncoding");

    if (encoding == null)
        encoding = "UTF-8";
}

public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain next) throws IOException, ServletException {
    // Respect the client-specified character encoding
    // (see HTTP specification section 3.4.1)
    if (null == request.getCharacterEncoding())
        request.setCharacterEncoding(encoding);

    /**
     * Set the default response content type and encoding
     */
    response.setContentType("text/html; charset=UTF-8");
    response.setCharacterEncoding("UTF-8");

    next.doFilter(request, response);
}

public void destroy() {
}

我在 localhost 中没有土耳其字符问题。我只在 www.gurkanilleez.com 中看到问题。

【问题讨论】:

  • 我解决了 jdbc:mysql://localhost:3306/dbname?characterEncoding=UTF-8 的问题,只是追加 'characterEncoding=UTF-8'

标签: java mysql tomcat encoding tomcat7


【解决方案1】:

由于我的声誉,我无法发表评论。我访问了您的网站,我看到了应有的土耳其字符。那么,有没有问题呢?

【讨论】:

  • 输入字段发送到数据库时出现问题。
【解决方案2】:

每个非英文字符的问号?可能发生了什么:

  • 你有 utf8 编码的数据(好)
  • SET NAMES latin1 生效(默认,但错误)
  • 该列被声明为CHARACTER SET latin1(默认,但错误)

使用 utf8 代替 latin1。

对于 JDBC,在 getConnection() 调用中包含 ?useUnicode=yes&characterEncoding=UTF-8

stackoverflow中有几个关于土耳其语字符集问题的帖子;阅读它们。

【讨论】:

  • 我正在使用休眠。我尝试了您的解决方案,但完全没有效果
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-30
  • 2012-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多