客户端设置:
$.ajax({
type: "Get",
url: encodeURI(goUrl),
dataType: "text",
success: function (data) {
alert(data);
return true;
}
})
用encodeURI使js强制转码成utf8
服务器端:
@RequestMapping(method = RequestMethod.GET, produces="text/plain;charset=UTF-8")
public @ResponseBody String initForm(ModelMap model, @RequestParam("status") String status) {
同时,还要确保web容器utf8编码,以jboss7.1为例,配置standalone.xml:
<system-properties>
<property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>
<property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true"/>
</system-properties>