Java 怎么从servlet获取异步Content

2019年8月17日22:05:01 评论 24

1.简介

Java 怎么从servlet获取异步Content?——请看下文。

2.代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */

import javax.servlet.AsyncContext;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class Main{
    public static AsyncContext getAsyncContext(ServletRequest request,
            ServletResponse response) {
        AsyncContext asyncContext = null;
        if (request.isAsyncStarted()) {
            asyncContext = request.getAsyncContext();
        } else {
            asyncContext = request.startAsync(request, response);
            asyncContext.setTimeout(20000);
        }
        return asyncContext;
    }
}

 

3.总结

示例代码演示了 Java 怎么从servlet获取异步Content,具体步骤参见示例代码。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: