java response.flushbuffer_Java ServletResponse.flushBuffer方法代碼示例

java response.flushbuffer_Java ServletResponse.flushBuffer方法代碼示例importjavax.servlet.ServletResponse;//導入方法依賴的package包/類/***HandletheHTTPstatuscode(andcorrespondingmessage)generated*whileprocessingthespecifiedRequesttoproducethespecified*Respon…

import javax.servlet.ServletResponse; //導入方法依賴的package包/類

/**

* Handle the HTTP status code (and corresponding message) generated

* while processing the specified Request to produce the specified

* Response. Any exceptions that occur during generation of the error

* report are logged and swallowed.

*

* @param request The request being processed

* @param response The response being generated

*/

protected void status(Request request, Response response) {

// Do nothing on non-HTTP responses

if (!(response instanceof HttpResponse))

return;

HttpResponse hresponse = (HttpResponse) response;

if (!(response.getResponse() instanceof HttpServletResponse))

return;

int statusCode = hresponse.getStatus();

String message = RequestUtil.filter(hresponse.getMessage());

if (message == null)

message = “”;

// Handle a custom error page for this status code

Context context = request.getContext();

if (context == null)

return;

ErrorPage errorPage = context.findErrorPage(statusCode);

if (errorPage != null) {

response.setAppCommitted(false);

ServletRequest sreq = request.getRequest();

ServletResponse sresp = response.getResponse();

sreq.setAttribute(Globals.STATUS_CODE_ATTR,

new Integer(statusCode));

sreq.setAttribute(Globals.ERROR_MESSAGE_ATTR,

message);

Wrapper wrapper = request.getWrapper();

if (wrapper != null)

sreq.setAttribute(Globals.SERVLET_NAME_ATTR,

wrapper.getName());

if (sreq instanceof HttpServletRequest)

sreq.setAttribute(Globals.EXCEPTION_PAGE_ATTR,

((HttpServletRequest) sreq).getRequestURI());

if (custom(request, response, errorPage)) {

try {

sresp.flushBuffer();

} catch (IOException e) {

log(“Exception Processing ” + errorPage, e);

}

}

}

}

今天的文章java response.flushbuffer_Java ServletResponse.flushBuffer方法代碼示例分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/5899.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注