本文整理匯總了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);
}
}