bfc87192c172b90167f13e3dc1633b24cf7f041a.svn-base 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package cn.com.goldenwater.dcproj.utils;
  2. import cn.com.goldenwater.core.web.BaseResponse;
  3. import net.sf.json.JSONObject;
  4. import javax.servlet.http.HttpServletResponse;
  5. import java.io.PrintWriter;
  6. public class ReturnUtils {
  7. /**
  8. * 输出失败信息
  9. * */
  10. public static void responseFail(HttpServletResponse response,String message,int code)throws Exception{
  11. BaseResponse baseResponse = new BaseResponse();
  12. baseResponse.setSuccess(false);
  13. baseResponse.setMessage(message);
  14. baseResponse.setCode(code);
  15. JSONObject expire = JSONObject.fromObject(baseResponse);
  16. response.setCharacterEncoding("UTF-8");
  17. response.setContentType("text/html;charset=utf-8");
  18. PrintWriter out = response.getWriter();
  19. out.print(expire.toString());
  20. out.flush();
  21. out.close();
  22. }
  23. /**
  24. * 输出格式化返回数据
  25. * */
  26. public static BaseResponse retFileResponse(int code,String message){
  27. BaseResponse baseResponse = new BaseResponse();
  28. baseResponse.setSuccess(false);
  29. baseResponse.setMessage(message);
  30. baseResponse.setCode(code);
  31. return baseResponse ;
  32. }
  33. }