厉害了,Servlet3的异步处理机制
Servlet3发布好几年了,又有多少人知道它的新特性呢?下面简单介绍下。 主要增加了以下特性: 1、异步处理支持 2、可插性支持 3、注解支持,零配置,可不用配置web.xml ... 异步处理是什么鬼? 直接操起键盘干。 @WebServlet(name = "index", urlPatterns = { "/" }, asyncSupported = true) public class IndexServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/html"); try { PrintWriter out = resp.getWriter(); out.println("servlet started.<br/>"); out.flush(); AsyncContext asyncContext = req.startAsync(); asyncContext.addListener(getListener()); asyncContext.start(new