我知道这是一个愚蠢的问题,但我没有通过 Google 找到预期的答案。 Spring MVC 4.3的一个新特性是支持配置JSON前缀
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="jsonPrefix" value=")]}',\n" />
</bean>
</mvc:message-converters>
因此 JSON 输入/输出看起来像:
)]}',\n"{\"userName\":\"ABC\",\"emailId\":\"ABC@gmail.com\"}"
我知道这是出于安全目的。但具体是关于什么的?
最佳答案
如果你看另一种添加的方法setPrefixJson(boolean) in the Spring JavaDoc你会明白背后的原因:
Indicate whether the JSON output by this view should be prefixed with ")]}', ". Default is false.
Prefixing the JSON string in this manner is used to help prevent JSON Hijacking. The prefix renders the string syntactically invalid as a script so that it cannot be hijacked. This prefix should be stripped before parsing the string as JSON.
关于java - JSON前缀有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41082479/