我已将数据库变量更改为 UTF8
- character_set_client utf8
- character_set_connection utf8
- character_set_database utf8
- character_set_filesystem 二进制文件
- character_set_results utf8
- character_set_server utf8
- 字符集系统 utf8
还在jsp上添加了包含的标签:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
但是当输入非英语文本时,它会被转换并以 html 实体的形式存储,即 #&number format
我想以Unicode
代码点格式输入它,例如\u6709
,而不使用任何java
代码转换器程序:
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form id="storeMsgForm" method="post" action="createnewmessage" >
<input type="text" name="msg_code">
<input type="text" name="message">
<input type="submit" id="saveEmployee" class="btn btn-primary" value="Save">
</form>
<c:forEach var="listvalue" items="${allMsg.allmessage}">
${listvalue.msg_code}
${listvalue.message}
<br/>
</c:forEach>
<%
if (request.getCharacterEncoding() == null) {
request.setCharacterEncoding("UTF-8");
}
%>
</body>
</html>
最佳答案
由于表单缺少 UTF-8 接受字符集,浏览器将输入中的特殊 Unicode 代码点转换为 HTML 实体。浏览器认为服务器发布的表单结果不能采用 UTF-8 格式。
<form id="storeMsgForm" method="post" action="createnewmessage" accept-charset="UTF-8">
关于java - 使用jsp在mysql中保存unicode代码点而不是html实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37787752/