本文整理汇总了Java中javax.servlet.http.HttpServletResponse.getCharacterEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletResponse.getCharacterEncoding方法的具体用法?Java HttpServletResponse.getCharacterEncoding怎么用?Java HttpServletResponse.getCharacterEncoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.HttpServletResponse
的用法示例。
在下文中一共展示了HttpServletResponse.getCharacterEncoding方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractResponseResult
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
* 提取请求结果
* @param request
* @param loggingContext
* @return
*/
protected Object extractResponseResult(HttpServletResponse response, LoggingContext loggingContext) throws Exception {
MediaType contentType = loggingContext.getHttpAccessLog().getResponseContentType();
if(contentType != null){
if(isContentCachingResponse(response)){
String charset = response.getCharacterEncoding();
if(StringUtils.isEmpty(charset)){
charset = StringUtils.defaultIfEmpty(contentType.getCharset().name(), GlobalConstants.SYSTEM_DEFAULT_CHARSET);
}
ContentCachingResponseWrapper responseToUse = (ContentCachingResponseWrapper) response;
byte[] bytes = responseToUse.getContentAsByteArray();
if(bytes != null){
return IOUtils.toString(bytes, charset);
}
}
}
return null;
}
示例2: render
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public Object render(ActionRequest actionRequest) throws Exception {
final HttpServletResponse response = actionRequest.response;
final String encoding = response.getCharacterEncoding();
response.setContentType(MimeTypes.MIME_APPLICATION_JSON);
response.setCharacterEncoding(encoding);
final Writer out = response.getWriter();
try {
SERIALIZER.serialize(this, out);
} finally {
out.flush();
}
return null;
}
示例3: render
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public Object render(final ActionRequest actionRequest) throws IOException {
final HttpServletResponse response = actionRequest.response;
final String encoding = response.getCharacterEncoding();
response.setContentType(this.mimetype);
response.setCharacterEncoding(encoding);
final Writer writer = response.getWriter();
final int size;
final String[] buffer;
size = (buffer = this.array).length;
try {
for (int i = 0; i < size; i++) {
writer.write(buffer[i]);
}
} finally {
writer.close();
}
return null;
}
示例4: UrlRewritingResponseWrapper
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
* Basic constructor.
*
* pock: For BES we use a new server for every request. We can't determine
* this server from the serverChain --> use the server of the request as
* parameter (Bug 5487)
*
* @param response
* The response we are wrapping
* @param server
* The server that was matched
* @param ownHostName
* String we are rewriting servers to
* @throws IOException
* When there is a problem with the streams
*/
public UrlRewritingResponseWrapper(HttpServletResponse response,
Server server, String ownHostName, String contextPath,
ServerChain serverChain) throws IOException {
super(response);
this.server = server;
this.ownHostName = ownHostName;
this.contextPath = contextPath;
this.serverChain = serverChain;
log = LogFactory.getLog(UrlRewritingResponseWrapper.class);
outStream = new UrlRewritingOutputStream(response.getOutputStream(),
contextPath, response
.getCharacterEncoding());
outWriter = new PrintWriter(outStream);
originalWriter = new PrintWriter(response.getOutputStream());
}
示例5: render
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public Object render(final ActionRequest actionRequest) throws IOException {
final HttpServletResponse response = actionRequest.response;
final String encoding = response.getCharacterEncoding();
response.setContentType(this.mimetype);
response.setCharacterEncoding(encoding);
ServletUtil.setResponseContent(response, this.data.getBytes(encoding));
return null;
}
示例6: renderJson
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public static Object renderJson(ActionRequest actionRequest, Object value, String boxName, String[] profiles) throws IOException {
final HttpServletResponse response = actionRequest.response;
final String encoding = response.getCharacterEncoding();
response.setContentType(MimeTypes.MIME_APPLICATION_JSON);
response.setCharacterEncoding(encoding);
final OutputStream out = response.getOutputStream();
try {
if (value == null) {
out.write("{}".getBytes(encoding));
return null;
}
final boolean hasBox = (boxName != null && !boxName.isEmpty());
final StringBuilder buffer = new StringBuilder(255);
if (hasBox) {
buffer.append("{\"").append(boxName).append("\":");
}
if (value instanceof Integer) {
buffer.append((Integer) value);
} else if (value instanceof String) {
StringUtil.escapeUTF8((String) value, buffer, true);
} else {
Json.writeTo(buffer, value, profiles);
}
if (hasBox) {
buffer.append('}');
}
out.write(buffer.toString().getBytes(encoding));
} finally {
//Notice: no close
out.flush();
}
return null;
}
示例7: forwardToString
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public String forwardToString(String url) throws ServletException, IOException
{
StringWriter sout = new StringWriter();
StringBuffer buffer = sout.getBuffer();
HttpServletResponse realResponse = getHttpServletResponse();
HttpServletResponse fakeResponse = new SwallowingHttpServletResponse(realResponse, sout, realResponse.getCharacterEncoding());
HttpServletRequest realRequest = getHttpServletRequest();
realRequest.setAttribute(WebContext.ATTRIBUTE_DWR, Boolean.TRUE);
getServletContext().getRequestDispatcher(url).forward(realRequest, fakeResponse);
return buffer.toString();
}
示例8: RewriteIvcResponseWrapper
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public RewriteIvcResponseWrapper(HttpServletResponse response, String tag) {
super(response);
this.tag = tag;
this.response = response;
try {
this.outputStream = response.getOutputStream();
// 由于tomcat等实现类会记录是否调用了getOutputStream方法,故此处进行这种操作
response.reset();
}
catch (IOException e) {
// 出现异常时则将异常信息放入
builder.append(e.toString());
}
this.rewriteOutStream = new RewriteIvcOutputStream(outputStream, response.getCharacterEncoding());
}
示例9: setCommonHeader
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public static void setCommonHeader(HttpServletResponse response) {
String encoding = response.getCharacterEncoding();
if(StringUtils.isBlank(encoding)) {
encoding = "UTF-8";
response.setCharacterEncoding(encoding);
}
response.setContentType("text/html");
response.setHeader("Content-Type", "text/html;charset=" + encoding);
}
示例10: setContentAndContentType
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public static void setContentAndContentType(final HttpServletResponse response, final String mimetype, final String context) throws IOException {
final String encoding = response.getCharacterEncoding();
response.setContentType(mimetype);
response.setCharacterEncoding(encoding);
ServletUtil.setResponseContent(response, context.getBytes(encoding));
}
示例11: doFilter
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
// cast once
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
// indicate that we're in SSI processing
req.setAttribute(Globals.SSI_FLAG_ATTR, "true");
// setup to capture output
ByteArrayServletOutputStream basos = new ByteArrayServletOutputStream();
ResponseIncludeWrapper responseIncludeWrapper = new ResponseIncludeWrapper(config.getServletContext(), req, res,
basos);
// process remainder of filter chain
chain.doFilter(req, responseIncludeWrapper);
// we can't assume the chain flushed its output
responseIncludeWrapper.flushOutputStreamOrWriter();
byte[] bytes = basos.toByteArray();
// get content type
String contentType = responseIncludeWrapper.getContentType();
// is this an allowed type for SSI processing?
if (contentTypeRegEx.matcher(contentType).matches()) {
String encoding = res.getCharacterEncoding();
// set up SSI processing
SSIExternalResolver ssiExternalResolver = new SSIServletExternalResolver(config.getServletContext(), req,
res, isVirtualWebappRelative, debug, encoding);
SSIProcessor ssiProcessor = new SSIProcessor(ssiExternalResolver, debug, allowExec);
// prepare readers/writers
Reader reader = new InputStreamReader(new ByteArrayInputStream(bytes), encoding);
ByteArrayOutputStream ssiout = new ByteArrayOutputStream();
PrintWriter writer = new PrintWriter(new OutputStreamWriter(ssiout, encoding));
// do SSI processing
long lastModified = ssiProcessor.process(reader, responseIncludeWrapper.getLastModified(), writer);
// set output bytes
writer.flush();
bytes = ssiout.toByteArray();
// override headers
if (expires != null) {
res.setDateHeader("expires", (new java.util.Date()).getTime() + expires.longValue() * 1000);
}
if (lastModified > 0) {
res.setDateHeader("last-modified", lastModified);
}
res.setContentLength(bytes.length);
Matcher shtmlMatcher = shtmlRegEx.matcher(responseIncludeWrapper.getContentType());
if (shtmlMatcher.matches()) {
// Convert shtml mime type to ordinary html mime type but
// preserve
// encoding, if any.
String enc = shtmlMatcher.group(1);
res.setContentType("text/html" + ((enc != null) ? enc : ""));
}
}
// write output
OutputStream out = null;
try {
out = res.getOutputStream();
} catch (IllegalStateException e) {
// Ignore, will try to use a writer
}
if (out == null) {
res.getWriter().write(new String(bytes));
} else {
out.write(bytes);
}
}