处理Struts2的action中对返回的json在另一端接收乱码问题
来源:互联网 发布:beowulf linux 编辑:程序博客网 时间:2024/05/17 13:43
private JSONObject result;
private IAppService ssuAppService;
public String getApps(){
logger.info("OuterInterfaceAction getApps()..start" );
result = new JSONObject();
try {
List<App> listApp = ssuAppService.getAppList();
if(null==listApp||listApp.size()<1){
result.put("returnCode", "10");
result.put("returnMsg", "app不存在");
return SUCCESS;
}
JsonConfig jsonConfig = new JsonConfig(); //建立配置文件
jsonConfig.setIgnoreDefaultExcludes(false);
jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
jsonConfig.setExcludes(new String[]{"deviceType","className","entityDescription","objectDescription","objectID","objectName"}); //jsconfig 设置过滤属性
result.put("returnCode", "00");
result.put("returnMsg", "认证成功");
response.setContentType("text/html;charset=GBK");//转换成你需要接收字符的编码
response.getWriter().write(result.toString());
response.getWriter().flush();
} catch (Exception e) {
result.put("returnCode", "-1");
result.put("returnMsg", "认证失败,接口发生异常");
e.printStackTrace();
return SUCCESS;
}
}
private IAppService ssuAppService;
public String getApps(){
logger.info("OuterInterfaceAction getApps()..start" );
result = new JSONObject();
try {
List<App> listApp = ssuAppService.getAppList();
if(null==listApp||listApp.size()<1){
result.put("returnCode", "10");
result.put("returnMsg", "app不存在");
return SUCCESS;
}
JsonConfig jsonConfig = new JsonConfig(); //建立配置文件
jsonConfig.setIgnoreDefaultExcludes(false);
jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
jsonConfig.setExcludes(new String[]{"deviceType","className","entityDescription","objectDescription","objectID","objectName"}); //jsconfig 设置过滤属性
result.put("returnCode", "00");
result.put("returnMsg", "认证成功");
result.put("extraInfo", JSONArray.fromObject(listApp, jsonConfig).toString());
//处理编码开始
HttpServletResponse response = ServletActionContext.getResponse();response.setContentType("text/html;charset=GBK");//转换成你需要接收字符的编码
response.getWriter().write(result.toString());
response.getWriter().flush();
response.getWriter().close();
//转码结束
return SUCCESS;} catch (Exception e) {
result.put("returnCode", "-1");
result.put("returnMsg", "认证失败,接口发生异常");
e.printStackTrace();
return SUCCESS;
}
}
0 0
- 处理Struts2的action中对返回的json在另一端接收乱码问题
- struts2中通过Action以InputStream的下载文件以及在iOS以及Android端接收的实现方式
- struts2中通过Action以InputStream的下载文件以及在iOS以及Android端接收的实现方式
- 在rails 中对返回的json 进行 错误处理
- struts2的action中返回json格式的数据
- Struts2的action中处理JSONP方式提交的中文乱码问题:
- Struts2里的Action返回Json数据
- Struts2中Action返回Json
- 关于在servlet和action中返回json数据的一些问题
- 关于struts2获取action中提示消息在jsp页面乱码的问题
- 在Action中以Struts2的方式输出JSON数据
- 在Action中以Struts2的方式输出JSON数据
- 在Action中以Struts2的方式输出JSON数据
- 在Action中以Struts2的方式输出JSON数据
- 在Action中以Struts2的方式输出JSON数据
- Struts2中action之间传参中文乱码的问题
- jQuery.Post到Struts2的action处理,并返回json对象到前端
- struts2 中对Action连续请求的问题
- Introduction to the Transport Control Protocol (TCP) 1
- HDU 5000 Clone / 2014 ACM/ICPC Asia Regional Anshan Online
- 在U-Boot中添加命令
- j2ee规范——JDBC
- 模版的特化和偏特化
- 处理Struts2的action中对返回的json在另一端接收乱码问题
- Prefab in Prefab
- 唐山昌欣泰机械有限公司 1
- HTTP 协议详解
- 唐山大弘欣商贸有限公司 1
- 深圳胡购贸易有限公司 1
- 上海赛力乐酒业发展有限公司 1
- 扬州宝祥节能科技有限公司 1
- 图像处理之常见二值化方