javascript - 我在 React/Java 中有一个字符编码程序。一切都设置为 UTF-8,但我的一个字符显示不正确
问题描述
前端是 React/JS,我有以下 div:
<div>
<Modal
isOpen={openCfcOverlay}
style={customStyles}
contentLabel="modal"
>
<div className="download-content">
<div id="download-title">Please make sure your Information is Correct...</div>
<form id="download-reach-form" onSubmit={(event) => this.handleSubmit(event)}>
<Input
errorMessage='Please enter a valid Street Address'
error={cfcDeclaration.companyAddress1Error}
title="Street Address"
type="text"
name="Street Address"
value={typeof selectedCompany == 'undefined' ? "" : selectedCompany.streetAddress1}
disabled='edit'
/>
<Input
errorMessage='Please enter a valid Street Address Cont.'
error={cfcDeclaration.companyAddress2Error}
title="Street Address Cont."
type="text"
name="Street Address Cont."
value={typeof selectedCompany == 'undefined' ? "" : selectedCompany.streetAddress2}
disabled='edit'
/>
</div>
</Modal>
在 index.template.html 文件中,设置了 utf-8:
<!DOCTYPE html>
<html lang="en">
<head>
<title>My page</title>
<meta charset="utf-8">
但在 UI 中,“é”符号显示为“é”。
示例:Amelié = Amelié©
它看起来像一个前端问题,但我如何在 React 中解决这个问题?
后端是Java,通过Maven完成配置。这也设置为 utf-8:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
街道地址作为 json 传递到后端:
public addressRequest(JSONObject jsonObject) {
this.streetAddress1 = (String) jsonObject.get("streetAddress1");
this.streetAddress2 = (String) jsonObject.get("streetAddress2");
@GET
@PermitAll
@Path("/download")
@ApiOperation(value = "Get information")
@ApiResponses(value = { @ApiResponse(code = 404, message = "not found")})
Response exportInfo(
@CookieParam(value = "userId") String userId,
@CookieParam(value = "token") String token,
@ApiParam(value = "streetAddress", required = true) @QueryParam("streetAddress") String streetAddress
) throws GeneralSecurityException, IOException;
但我觉得罪魁祸首是前端,因为我可以在通过开发工具检查元素时看到错误的地址名称:
<input class="input-component" type="text" name="Street Address" value="Amelié" data-reactid=".2.0.0.1.4.0.1">
而不是阿梅利埃。
如果重要的话,输入组件的 index.less ......
.input-component {
background: #ECECEC;
border: 2px solid #ECECEC;
color: #000;
display: inline-block;
font-weight: normal;
width: 226px;
&.wide {
width: 484px;
}
}
.input-component::-webkit-input-placeholder {
color: @black;
opacity: 1 !important;
}
.input-component:-moz-placeholder {
color: @black;
opacity: 1 !important;
}
.input-component::-moz-placeholder {
color: @black;
opacity: 1 !important;
}
.input-component:-ms-placeholder {
color: @black;
opacity: 1 !important;
我已经尝试了很多东西,但无法让 é 显示。我知道这是一个 utf-8 问题,因为我使用了一个将字符串转换为 utf-8 的在线工具,并且我从不正确的符号中得到了 'é'。我还可以做些什么 ?
解决方案
推荐阅读
- asp.net - 如何在 Visual Studio 2015 中使用 MSBuild 在构建时部署 ASP.NET MVC 应用程序?
- dart - 等待子树小部件完成加载异步数据,然后再显示它们
- dictionary - 添加两个地图的惯用/Groovy 方式,其中任何一个都可能为空
- php - Laravel Nova 自我参照关系
- c++ - 完美的转发/移动构造不适用于 std::apply 中的元组
- here-api - here-api 矩阵路由摘要与使用相同 routeId 调用 getroute 时得到的不同 - 为什么会这样?
- android - 适用于 Android 6 和 7/8 的位置权限问题
- sql - 从 2 个表中查询匹配条件的 SQL
- python - Paramiko - 错误的身份验证类型 [Cisco SG-300 交换机]
- php - PHPML库问题