本文整理汇总了Java中org.springframework.extensions.webscripts.WebScriptResponse.setHeader方法的典型用法代码示例。如果您正苦于以下问题:Java WebScriptResponse.setHeader方法的具体用法?Java WebScriptResponse.setHeader怎么用?Java WebScriptResponse.setHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.extensions.webscripts.WebScriptResponse
的用法示例。
在下文中一共展示了WebScriptResponse.setHeader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import org.springframework.extensions.webscripts.WebScriptResponse; //导入方法依赖的package包/类
private void handle(WebScriptRequest req, WebScriptResponse res) throws JSONException, IOException
{
// create map of template vars
String modelQName = req.getParameter("modelQName");
if(modelQName == null)
{
throw new WebScriptException(
Status.STATUS_BAD_REQUEST,
"URL parameter 'modelQName' not provided.");
}
ModelDefinition.XMLBindingType bindingType = ModelDefinition.XMLBindingType.DEFAULT;
AlfrescoModel model = solrTrackingComponent.getModel(QName.createQName(modelQName));
res.setHeader("XAlfresco-modelChecksum", String.valueOf(model.getModelDef().getChecksum(bindingType)));
model.getModelDef().toXML(bindingType, res.getOutputStream());
}
示例2: streamContentImpl
import org.springframework.extensions.webscripts.WebScriptResponse; //导入方法依赖的package包/类
protected void streamContentImpl(WebScriptRequest req, WebScriptResponse res,
ContentReader reader, NodeRef nodeRef, QName propertyQName,
boolean attach, Date modified, String eTag, String attachFileName)
throws IOException
{
delegate.setAttachment(req, res, attach, attachFileName);
// establish mimetype
String mimetype = reader.getMimetype();
String extensionPath = req.getExtensionPath();
if (mimetype == null || mimetype.length() == 0)
{
mimetype = MimetypeMap.MIMETYPE_BINARY;
int extIndex = extensionPath.lastIndexOf('.');
if (extIndex != -1)
{
String ext = extensionPath.substring(extIndex + 1);
mimetype = mimetypeService.getMimetype(ext);
}
}
// set mimetype for the content and the character encoding + length for the stream
res.setContentType(mimetype);
res.setContentEncoding(reader.getEncoding());
res.setHeader("Content-Length", Long.toString(reader.getSize()));
// set caching
Cache cache = new Cache();
cache.setNeverCache(false);
cache.setMustRevalidate(true);
cache.setMaxAge(0L);
cache.setLastModified(modified);
cache.setETag(eTag);
res.setCache(cache);
}
示例3: setAttachment
import org.springframework.extensions.webscripts.WebScriptResponse; //导入方法依赖的package包/类
/**
* Set attachment header
*
* @param req WebScriptRequest
* @param res WebScriptResponse
* @param attach boolean
* @param attachFileName String
*/
public void setAttachment(WebScriptRequest req, WebScriptResponse res, boolean attach, String attachFileName)
{
if (attach == true)
{
String headerValue = "attachment";
if (attachFileName != null && attachFileName.length() > 0)
{
if (logger.isDebugEnabled())
logger.debug("Attaching content using filename: " + attachFileName);
if (req == null)
{
headerValue += "; filename*=UTF-8''" + URLEncoder.encode(attachFileName)
+ "; filename=\"" + filterNameForQuotedString(attachFileName) + "\"";
}
else
{
String userAgent = req.getHeader(HEADER_USER_AGENT);
boolean isLegacy = (null != userAgent) && (userAgent.contains("MSIE 8") || userAgent.contains("MSIE 7"));
if (isLegacy)
{
headerValue += "; filename=\"" + URLEncoder.encode(attachFileName);
}
else
{
headerValue += "; filename=\"" + filterNameForQuotedString(attachFileName) + "\"; filename*=UTF-8''"
+ URLEncoder.encode(attachFileName);
}
}
}
// set header based on filename - will force a Save As from the browse if it doesn't recognize it
// this is better than the default response of the browser trying to display the contents
res.setHeader("Content-Disposition", headerValue);
}
}