Example usage for org.springframework.web.util WebUtils CONTENT_TYPE_CHARSET_PREFIX

List of usage examples for org.springframework.web.util WebUtils CONTENT_TYPE_CHARSET_PREFIX

Introduction

In this page you can find the example usage for org.springframework.web.util WebUtils CONTENT_TYPE_CHARSET_PREFIX.

Prototype

String CONTENT_TYPE_CHARSET_PREFIX

To view the source code for org.springframework.web.util WebUtils CONTENT_TYPE_CHARSET_PREFIX.

Click Source Link

Document

Prefix of the charset clause in a content type String: ";charset=".

Usage

From source file:ua.com.manometer.jasperreports.AbstractJasperReportsSingleFormatView.java

/**
 * We need to write text to the response Writer.
 * @param exporter the JasperReports exporter to use
 * @param populatedReport the populated <code>JasperPrint</code> to render
 * @param response the HTTP response the report should be rendered to
 * @throws Exception if rendering failed
 *///from  w w  w.j a  v  a  2  s . c o m
protected void renderReportUsingWriter(JRExporter exporter, JasperPrint populatedReport,
        HttpServletResponse response) throws Exception {

    // Copy the encoding configured for the report into the response.
    String contentType = getContentType();
    String encoding = (String) exporter.getParameter(JRExporterParameter.CHARACTER_ENCODING);
    if (encoding != null) {
        // Only apply encoding if content type is specified but does not contain charset clause already.
        if (contentType != null && !contentType.toLowerCase().contains(WebUtils.CONTENT_TYPE_CHARSET_PREFIX)) {
            contentType = contentType + WebUtils.CONTENT_TYPE_CHARSET_PREFIX + encoding;
        }
    }
    response.setContentType(contentType);

    // Render report into HttpServletResponse's Writer.
    JasperReportsUtils.render(exporter, populatedReport, response.getWriter());
}