我在netbeans 8.0.2项目和glassfish服务器开源版4.1中使用了servlet和JPA以及entityManager和JDK 1.8。
我的netbeans项目源设置为utf8。
我的MySQL数据库设置为utf8-默认排序规则以及我的所有表格。
当我插入新数据时,我在表格中收到了装饰字符。
我在glassfish-ressource.xml中有这些属性
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="mysql_mysql_rootPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="serverName" value="localhost"/>
<property name="User" value="root"/>
<property name="Password" value="root"/>
<property name="URL" value="jdbc:mysql://localhost:3306/miniwiki?zeroDateTimeBehavior=convertToNull&useUnicode=yes&characterEncoding=UTF-8"/>
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
</jdbc-connection-pool>
我的persistence.xml中的这些属性
<properties>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
<property name="eclipselink.logging.level" value="ALL"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/miniwiki?zeroDateTimeBehavior=convertToNull&useUnicode=yes&characterEncoding=UTF-8"/>
</properties>
但我必须在我的请求中设置这样的utf8
request.setCharacterEncoding("UTF-8");
我的所有html页面都设置为utf-8
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"></meta>
<meta content="IE=edge" http-equiv="X-UA-Compatible"></meta>
<meta content="width=device-width, initial-scale=1" name="viewport"></meta>
<meta content="" name="description"></meta>
<meta content="" name="author"></meta>
<link href="../../favicon.ico" rel="icon"></link>
我的所有.jsp页面都以
开头<%@page contentType="text/html" pageEncoding="UTF-8"%>
我的日志详细信息
Config: Connected: jdbc:mysql://localhost:3306/miniwiki?zeroDateTimeBehavior=convertToNull&useUnicode=yes&characterEncoding=UTF-8