Search in sources :

Example 1 with RenderException

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);
    }
}
Also used : RenderException(com.jfinal.render.RenderException) IOException(java.io.IOException)

Example 2 with RenderException

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);
            }
        }
    }
}
Also used : Cookie(javax.servlet.http.Cookie) RenderException(com.jfinal.render.RenderException) ServletOutputStream(javax.servlet.ServletOutputStream) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) RenderException(com.jfinal.render.RenderException)

Example 3 with RenderException

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();
        }
    }
}
Also used : RenderException(com.jfinal.render.RenderException) HashMap(java.util.HashMap) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap) Writer(java.io.Writer) IOException(java.io.IOException) RenderException(com.jfinal.render.RenderException) Template(freemarker.template.Template)

Example 4 with RenderException

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();
        }
    }
}
Also used : RenderException(com.jfinal.render.RenderException) RenderException(com.jfinal.render.RenderException) PrintWriter(java.io.PrintWriter)

Example 5 with RenderException

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();
    }
}
Also used : RenderException(com.jfinal.render.RenderException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Aggregations

RenderException (com.jfinal.render.RenderException)8 IOException (java.io.IOException)5 PrintWriter (java.io.PrintWriter)2 HashMap (java.util.HashMap)2 EncodeHintType (com.google.zxing.EncodeHintType)1 BitMatrix (com.google.zxing.common.BitMatrix)1 QRCodeWriter (com.google.zxing.qrcode.QRCodeWriter)1 Invocation (com.jfinal.aop.Invocation)1 Render (com.jfinal.render.Render)1 Template (freemarker.template.Template)1 BufferedImage (java.awt.image.BufferedImage)1 OutputStream (java.io.OutputStream)1 Writer (java.io.Writer)1 Map (java.util.Map)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 Cookie (javax.servlet.http.Cookie)1