controller
@RequestMapping(value = "/com/testjson", produces = { "text/plain;charset=UTF-8" }) public @ResponseBody String testjson(HttpServletRequest request){ Map<String,Object> m = new HashMap<String,Object>(); ...... return new JSONObject(m).toString(); }
页面
$(‘#testFm‘).form(‘submit‘, { url : ‘com/testjson‘, type : "POST", onSubmit : function() { ...... return validate; }, success : function(data) { data = $.parseJSON(data); ...... } });
web.xml 设置编码
<filter> <filter-name>encodingFilter</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>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
时间: 2024-10-13 23:27:26