0

我的网络项目(Java EE)中需要波兰语字符。当我在数据库中插入一行时,一切正常,但是当我尝试在我的页面中插入行时。在数据库中我看到了?而是波兰语字符。我在我的页面中设置了 UTF-8 编码:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

和 glassfish-web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
  <class-loader delegate="true"/>
  <parameter-encoding default-charset="UTF-8" />
  <jsp-config>
    <property name="keepgenerated" value="true">
      <description>Keep a copy of the generated servlet class' java code.</description>
    </property>
  </jsp-config>
</glassfish-web-app>

我还需要在哪里设置一些东西?

4

1 回答 1

0

确保将utf-8引擎设置为您的数据库。尝试作为字符编码连接到您的数据库连接。

jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8

为了更确定,您应该编写ServetFilter设置字符编码类型。我认为,

CharSetFilter.java

public class CharSetFilter implements Filter {
    public void init(FilterConfig fConfig) throws ServletException {
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        response.setCharacterEncoding("UTF-8");
        chain.doFilter(request, response);
    }

    public void destroy() {
    }
}

web.xml 配置

<filter>
    <filter-name>CharSet Filter</filter-name>
    <filter-class>your.package.CharSetFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>CharSet Filter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
于 2013-07-23T11:03:39.087 回答