use of app.hongs.HongsError in project HongsCORE by ihongs.
the class ActionHelper method responed.
// ** 跳转及错误 **/
/**
* 返回数据
* 将以 JSON/JSONP 格式输出, 编码 UTF-8
*/
public void responed() {
if (null == this.responseData) {
return;
}
// 动作调用了 forward 之后
// 这时再调用 getWriter 会抛 STREAM 异常
// 因容器调用 getOutputStream 来输出内容
// 所以必须将 OutputStream 包装成 Writer
Writer out;
try {
out = getOutputWriter();
} catch (IllegalStateException e) {
out = new PrintWriter(getOutputStream());
}
// 检查是否有 JSONP 的回调函数
String fun;
fun = getParameter(Cnst.CB_KEY);
if (fun == null || fun.isEmpty()) {
fun = getParameter(CoreConfig.getInstance().getProperty("core.act.call", "callback"));
}
// 此情况下需将回调包裹上 HTML.
try {
if (fun != null && fun.length() != 0) {
if (fun.startsWith("top.") || fun.startsWith("parent.") || fun.startsWith("opener.")) {
if (!this.response.isCommitted()) {
this.response.setCharacterEncoding("UTF-8");
this.response.setContentType("text/html");
}
out.append("<script type=\"text/javascript\">");
out.append(fun);
out.append("(");
Data.append(out, this.responseData);
out.append(");");
out.append("</script>");
} else {
if (!this.response.isCommitted()) {
this.response.setCharacterEncoding("UTF-8");
this.response.setContentType("text/javascript");
}
out.append(fun);
out.append("(");
Data.append(out, this.responseData);
out.append(");");
}
} else {
if (!this.response.isCommitted()) {
this.response.setCharacterEncoding("UTF-8");
this.response.setContentType("application/json");
}
Data.append(out, this.responseData);
}
} catch (IOException e) {
throw new HongsError(0x32, "Can not send to client.", e);
}
this.responseData = null;
}
use of app.hongs.HongsError in project HongsCORE by ihongs.
the class ActionHelper method updateHelper.
/**
* 供 ActionDriver 重设助手
* @param req
* @param rsp
*/
public final void updateHelper(HttpServletRequest req, HttpServletResponse rsp) {
this.request = req;
this.response = rsp;
try {
if (null != this.request) {
this.request.setCharacterEncoding("UTF-8");
}
if (null != this.response) {
this.response.setCharacterEncoding("UTF-8");
}
} catch (UnsupportedEncodingException ex) {
throw new HongsError(0x31, "Can not set encoding.", ex);
}
this.outputStream = null;
this.outputWriter = null;
}
Aggregations