java - 俄语字符显示为 ??? 在 Spring-MVC 中
问题描述
所以我创建了一个控制器
@Controller
@RequestMapping("/hello")
public class HelloController {
@RequestMapping("/all")
@ResponseBody
public String display()
{
return "Мегафон Игры"; //russian characters
}
}
现在,当我点击 url http://localhost:8080/SpringMVC/hello/all
时,我得到??????? ????
了响应。
我在tomcat的server.xml文件中配置了URIEncoding,如下所示
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>`
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/>
我已经在 Chrome 浏览器、邮递员和 Eclipse 控制台上测试了我的响应。
我什至尝试在 web.xml 文件中添加编码过滤器
<filter>
<filter-name>encoding-filter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>FALSE</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding-filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
请帮帮我我错过了什么?
解决方案
可能是您需要定义响应正文的编码。
为此,您可以使用@RequestMapping
注释,例如
@RequestMapping(
value = "/all",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_UTF8_VALUE
)
推荐阅读
- javascript - 无法读取使用 SheetJs 生成的 XLSX 的单元格值
- python - url 未在 Jupyter 的 folium 地图中打开
- javascript - Gojs 可调整大小的组
- r - 计算字符“;”两侧的字符串
- shell - 有没有办法使用 awk 总结单个标识符的第二个字段并用非数字替换输出?
- google-cloud-platform - Is it possible to save an Entire Project created via the console on Google Cloud Platform and restore it later?
- wpf - 当我放大程序时,为什么我的网格没有变大?
- swift - Could not load Main.Storyboard in XCUITest
- ms-access - MS Access 链接的 SharePoint 列表是只读的
- python - 两个矩阵有什么区别?