use of com.jfinal.render.RenderException in project jfinal by jfinal.
the class HandlerKit method redirect.
public static void redirect(String url, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
isHandled[0] = true;
String queryString = request.getQueryString();
if (queryString != null)
url = url + "?" + queryString;
try {
// always 302
response.sendRedirect(url);
} catch (IOException e) {
throw new RenderException(e);
}
}
use of com.jfinal.render.RenderException in project jfinal by jfinal.
the class CaptchaRender method render.
/**
* 生成验证码
*/
public void render() {
Captcha captcha = createCaptcha();
CaptchaManager.me().getCaptchaCache().put(captcha);
Cookie cookie = new Cookie(captchaName, captcha.getKey());
cookie.setMaxAge(-1);
cookie.setPath("/");
response.addCookie(cookie);
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
ServletOutputStream sos = null;
try {
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
drawGraphic(captcha.getValue(), image);
sos = response.getOutputStream();
ImageIO.write(image, "jpeg", sos);
} catch (IOException e) {
if (getDevMode()) {
throw new RenderException(e);
}
} catch (Exception e) {
throw new RenderException(e);
} finally {
if (sos != null) {
try {
sos.close();
} catch (IOException e) {
LogKit.logNothing(e);
}
}
}
}
use of com.jfinal.render.RenderException in project my_curd by qinyou.
the class FreeMarkerXMLRender method render.
@Override
public void render() {
response.setContentType(CONTENT_TYPE);
Enumeration<String> attrs = request.getAttributeNames();
Map root = new HashMap();
while (attrs.hasMoreElements()) {
String attrName = attrs.nextElement();
root.put(attrName, request.getAttribute(attrName));
}
Writer writer = null;
try {
writer = response.getWriter();
Template template = getConfiguration().getTemplate(view);
template.process(root, writer);
} catch (Exception e) {
throw new RenderException(e);
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of com.jfinal.render.RenderException in project my_curd by qinyou.
the class CsvRender method render.
@Override
public void render() {
response.reset();
PrintWriter out = null;
try {
response.setContentType("application/vnd.ms-excel;charset=" + encodeType);
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, encodeType));
out = response.getWriter();
out.write(CsvUtil.createCSV(headers, data, clomuns));
} catch (Exception e) {
throw new RenderException(e);
} finally {
if (null != out) {
out.flush();
out.close();
}
}
}
use of com.jfinal.render.RenderException in project fruit-manage by liuzhaozhao.
the class ErrorTextRender method render.
@SuppressWarnings("deprecation")
@Override
public void render() {
String encodeText = "";
PrintWriter writer = null;
try {
encodeText = URLEncoder.encode(errorText, "utf-8");
// 针对部分前端ajax框架(axios),错误消息设置到响应体里,页面上是获取不到的(jquery可以),需要使用该方式
response.setStatus(getErrorCode(), encodeText);
// response.sendError(getErrorCode(), encodeText);// 和上面的不同,这里会返回html格式,而上面仅会返回错误文本
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.addHeader("Error-Text", encodeText);
response.setContentType(contentType);
writer = response.getWriter();
writer.write(encodeText);
writer.flush();
} catch (IOException e) {
throw new RenderException(e);
} finally {
if (writer != null)
writer.close();
}
}
Aggregations