本文整理匯總了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();
}
}
示例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);
}
}
示例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();
}
}
示例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;
}
}
示例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-");
}
}
示例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");
}