servlet get Async Context - Java Servlet JSP

Java examples for Servlet JSP:Servlet

Description

servlet get Async Context

Demo Code


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

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

Related Tutorials