本文整理汇总了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");
}