兩個系統做數據傳輸時,懶省事,直接訪問 action 方式。結果總是報500,或者fileNotFount。
究其原因是因為兩邊的數據格式沒對應上。post請求返回的格式是String,數據提供方返回的數據格式Map啊JSON啊都不怎么對。只得返回了json.toString.。記錄一下,歡迎拍磚指導。
net.sf.json.JSONObject obj = net.sf.json.JSONObject.fromObject(resultMap); try { response.setCharacterEncoding("UTF-8"); response.setContentType("text/plain, utf-8"); PrintWriter out = response.getWriter(); out.print(obj.toString()); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } // return obj.toString();
return obj.toString(); 直接返回這個接受方會出現亂碼。
關於亂碼這個問題,網上也有其他解決方案:比如 mapping中增加produces
@Controller
@RequestMapping(value = "/query", produces = "text/html;charset=UTF-8")
public class QueryController {
@RequestMapping(value = "***",produces={"application/json;","text/html;charset=UTF-8;"})
可參見
http://blog.csdn.net/u010979495/article/details/50610856