为什么80%的码农都做不了架构师?>>>
pom.xml:
<dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.0.1</version><scope>provided</scope>
</dependency>
js异步请求有哪几种方式。
web.xml:
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"><display-name>Servlet3-Demo</display-name>
</web-app>
AsyncServlet:
@WebServlet(value = "/async-demo", asyncSupported = true)
public class AsyncServlet extends HttpServlet {ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2);public void doGet(HttpServletRequest req, HttpServletResponse res) {AsyncContext aCtx = req.startAsync(req, res);executor.execute(new AsyncHandler(aCtx));}}
java接口异步不等待, AsyncHandler:
public class AsyncHandler implements Runnable {private AsyncContext ctx;public AsyncHandler(AsyncContext ctx) {this.ctx = ctx;}@Overridepublic void run() {System.out.println("Dispatch Time: " + System.currentTimeMillis());ctx.dispatch("/index.jsp");}}