當前位置: 首頁>>代碼示例>>Java>>正文


Java AsyncContext.dispatch方法代碼示例

本文整理匯總了Java中javax.servlet.AsyncContext.dispatch方法的典型用法代碼示例。如果您正苦於以下問題:Java AsyncContext.dispatch方法的具體用法?Java AsyncContext.dispatch怎麽用?Java AsyncContext.dispatch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.AsyncContext的用法示例。


在下文中一共展示了AsyncContext.dispatch方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doGet

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    // Only set the status on the first call (the dispatch will trigger
    // another call to this Servlet)
    if (resp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) {
        resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        AsyncContext ac = req.startAsync();
        ac.dispatch();
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:12,代碼來源:TestErrorReportValve.java

示例2: doGet

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    AsyncContext ac = req.startAsync();
    // Quick and dirty. Sufficient for this test but ignores lots of
    // edge cases.
    String target = null;
    if (dispatchPath != null) {
        target = req.getServletPath();
        int lastSlash = target.lastIndexOf('/');
        target = target.substring(0, lastSlash + 1);
        if (encodePath) {
            target = URLEncoder.DEFAULT.encode(target, "UTF-8");
        }
        target += dispatchPath;
    }
    try {
        ac.dispatch(target);
    } catch (UnsupportedOperationException uoe) {
        ac.complete();
        resp.setContentType("text/plain");
        resp.setCharacterEncoding("UTF-8");
        resp.getWriter().print(NULL);
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:27,代碼來源:TestApplicationContextGetRequestDispatcher.java

示例3: doGet

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    TestAsyncContextImpl.track("DispatchingServletGet-");
    resp.flushBuffer();

    final boolean first = TrackingServlet.first;
    TrackingServlet.first = false;

    final AsyncContext ctxt = req.startAsync();
    TrackingListener listener = new TrackingListener(false, true, null);
    ctxt.addListener(listener);
    ctxt.setTimeout(3000);

    Runnable run = new Runnable() {
        @Override
        public void run() {
            if (first) {
                ctxt.dispatch("/stage1");
            } else {
                ctxt.dispatch("/stage2");
            }
        }
    };
    if ("y".equals(req.getParameter("useThread"))) {
        new Thread(run).start();
    } else {
        run.run();
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:31,代碼來源:TestAsyncContextImpl.java

示例4: doGet

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    TestAsyncContextImpl.track("AsyncErrorPageGet-");

    final AsyncContext ctxt = req.getAsyncContext();

    switch(mode) {
        case COMPLETE:
            TestAsyncContextImpl.track("Complete-");
            ctxt.complete();
            break;
        case DISPATCH:
            TestAsyncContextImpl.track("Dispatch-");
            ctxt.dispatch("/error/nonasync");
            break;
        case NO_COMPLETE:
            TestAsyncContextImpl.track("NoOp-");
            break;
        default:
            // Impossible
            break;
    }
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:25,代碼來源:TestAsyncContextImpl.java

示例5: service

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
@Override
public void service(ServletRequest req, ServletResponse resp)
        throws ServletException, IOException {
    if (DispatcherType.ASYNC != req.getDispatcherType()) {
        AsyncContext asyncContext;
        if ("y".equals(req.getParameter(CUSTOM_REQ_RESP))) {
            asyncContext = req.startAsync(
                    new ServletRequestWrapper(req),
                    new ServletResponseWrapper(resp));
        } else {
            asyncContext = req.startAsync();
        }
        if ("y".equals(req.getParameter(EMPTY_DISPATCH))) {
            asyncContext.dispatch();
        } else {
            asyncContext.dispatch("/target");
        }
        try {
            asyncContext.dispatch("/nonExistingServlet");
            TestAsyncContextImpl.track("FAIL");
        } catch (IllegalStateException e) {
            TestAsyncContextImpl.track("OK");
        }
    } else {
        TestAsyncContextImpl.track("DispatchingGenericServletGet-");
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:28,代碼來源:TestAsyncContextImpl.java

示例6: service

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    final AsyncContext actx = req.startAsync();
    actx.setTimeout(30*1000);
    actx.dispatch("/jsp/async/async3.jsp");
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:7,代碼來源:Async3.java


注:本文中的javax.servlet.AsyncContext.dispatch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。