本文整理匯總了Java中javax.servlet.http.HttpServletResponse.getContentType方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletResponse.getContentType方法的具體用法?Java HttpServletResponse.getContentType怎麽用?Java HttpServletResponse.getContentType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.servlet.http.HttpServletResponse
的用法示例。
在下文中一共展示了HttpServletResponse.getContentType方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendFallback
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
private void sendFallback(Integer size, HttpServletResponse response) throws IOException {
if (response.getContentType() == null) {
response.setContentType(StringUtil.getMimeType("jpeg"));
}
InputStream in = null;
try {
in = getClass().getResourceAsStream("default_cover.jpg");
BufferedImage image = ImageIO.read(in);
if (size != null) {
image = scale(image, size, size);
}
ImageIO.write(image, "jpeg", response.getOutputStream());
} finally {
IOUtils.closeQuietly(in);
}
}
示例2: putHeaders
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
public static void putHeaders(HttpServletResponse response, HttpContent content, long contentLength, boolean etag)
{
long lml=content.getResource().lastModified();
if (lml>=0)
response.setDateHeader(HttpHeader.LAST_MODIFIED.asString(),lml);
if (contentLength==0)
contentLength=content.getContentLengthValue();
if (contentLength >=0)
{
if (contentLength<Integer.MAX_VALUE)
response.setContentLength((int)contentLength);
else
response.setHeader(HttpHeader.CONTENT_LENGTH.asString(),Long.toString(contentLength));
}
String ct=content.getContentTypeValue();
if (ct!=null && response.getContentType()==null)
response.setContentType(ct);
String ce=content.getContentEncodingValue();
if (ce!=null)
response.setHeader(HttpHeader.CONTENT_ENCODING.asString(),ce);
if (etag)
{
String et=content.getETagValue();
if (et!=null)
response.setHeader(HttpHeader.ETAG.asString(),et);
}
}
示例3: isBinaryContent
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
private boolean isBinaryContent(final HttpServletResponse response) {
return response.getContentType() != null && (response.getContentType()
.startsWith("image") || response.getContentType().startsWith("video") || response
.getContentType().startsWith("audio"));
}
示例4: isMultipart
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
private boolean isMultipart(final HttpServletResponse response) {
return response.getContentType() != null && (response.getContentType()
.startsWith("multipart/form-data") || response.getContentType()
.startsWith("application/octet-stream"));
}