本文整理汇总了Java中org.springframework.web.util.WebUtils.CONTENT_TYPE_CHARSET_PREFIX属性的典型用法代码示例。如果您正苦于以下问题:Java WebUtils.CONTENT_TYPE_CHARSET_PREFIX属性的具体用法?Java WebUtils.CONTENT_TYPE_CHARSET_PREFIX怎么用?Java WebUtils.CONTENT_TYPE_CHARSET_PREFIX使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.springframework.web.util.WebUtils
的用法示例。
在下文中一共展示了WebUtils.CONTENT_TYPE_CHARSET_PREFIX属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureResponse
/**
* Configure the supplied {@link HttpServletResponse}.
* <p>The default implementation of this method sets the
* {@link HttpServletResponse#setContentType content type} and
* {@link HttpServletResponse#setCharacterEncoding encoding}
* from the "media-type" and "encoding" output properties
* specified in the {@link Transformer}.
* @param model merged output Map (never {@code null})
* @param response current HTTP response
* @param transformer the target transformer
*/
protected void configureResponse(Map<String, Object> model, HttpServletResponse response, Transformer transformer) {
String contentType = getContentType();
String mediaType = transformer.getOutputProperty(OutputKeys.MEDIA_TYPE);
String encoding = transformer.getOutputProperty(OutputKeys.ENCODING);
if (StringUtils.hasText(mediaType)) {
contentType = mediaType;
}
if (StringUtils.hasText(encoding)) {
// 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);
}
示例2: renderReportUsingWriter
/**
* We need to write text to the response Writer.
* @param exporter the JasperReports exporter to use
* @param populatedReport the populated {@code JasperPrint} to render
* @param response the HTTP response the report should be rendered to
* @throws Exception if rendering failed
*/
protected void renderReportUsingWriter(net.sf.jasperreports.engine.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(net.sf.jasperreports.engine.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());
}