日期:2014-05-16  浏览次数:20604 次

java 用ajax java后台传回值

?

? ? 用ajax java后台传回值,包括传json

?

  public static final void sendAsJson(HttpServletResponse response, String str)
  {
    response.setContentType("application/json;charset=UTF-8");
    if (null != str)
      try {
        response.getWriter().write(str);
      } catch (IOException e) {
        e.printStackTrace();
      }
  }

  public static final void sendAsText(HttpServletResponse response, String str)
  {
    response.setContentType("text/html;charset=UTF-8");
    if (null != str)
      try {
        response.getWriter().write(str);
      } catch (IOException e) {
        e.printStackTrace();
      }
  }
?