当前位置: 首页>>代码示例>>Java>>正文


Java HttpServletResponse.getCharacterEncoding方法代码示例

本文整理汇总了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;
}
 
开发者ID:penggle,项目名称:xproject,代码行数:24,代码来源:AbstractHttpAccessLoggingInterceptor.java

示例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;
}
 
开发者ID:febit,项目名称:febit,代码行数:17,代码来源:OutgoingResponse.java

示例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;
}
 
开发者ID:febit,项目名称:febit,代码行数:21,代码来源:TextPiece.java

示例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());
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:33,代码来源:UrlRewritingResponseWrapper.java

示例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;
}
 
开发者ID:febit,项目名称:febit,代码行数:10,代码来源:Text.java

示例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;
}
 
开发者ID:febit,项目名称:febit,代码行数:35,代码来源:RenderUtil.java

示例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();
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:16,代码来源:DefaultWebContext.java

示例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());
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:16,代码来源:RewriteIvcResponseWrapper.java

示例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);
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:11,代码来源:ResponseUtils.java

示例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));
}
 
开发者ID:febit,项目名称:febit,代码行数:7,代码来源:ServletUtil.java

示例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);
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:79,代码来源:SSIFilter.java


注:本文中的javax.servlet.http.HttpServletResponse.getCharacterEncoding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。