网站建设样板,西安网络公司网站建设,怎么做网页漂亮,wordpress使用手机号登录Servlet3是Tomcat7出现的新特性#xff0c;所以需要先安装tomcat7
微信企业号使用回调模式时#xff1a;
假如企业无法保证在五秒内处理并回复#xff0c;可以直接回复空串#xff0c;企业号不会对此作任何处理#xff0c;并且不会发起重试。这种情况下#xff0c;可以…Servlet3是Tomcat7出现的新特性所以需要先安装tomcat7
微信企业号使用回调模式时
假如企业无法保证在五秒内处理并回复可以直接回复空串企业号不会对此作任何处理并且不会发起重试。这种情况下可以使用发消息接口进行异步回复。 在web.xml中的servlet节点配置
async-supportedtrue/async-supported代码 AsyncServlet.java package testAsyncServlet;import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;public class AsyncServlet extends HttpServlet{private static final long serialVersionUID 1L;Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response.setContentType(text/html;charsetutf-8);PrintWriter out response.getWriter();out.println(下订单开始: new Date() br/);out.flush();AsyncContext ctx request.startAsync();//异步去执行开通订单new Thread(new CheckOrder(ctx)).start();out.println(订购成功: new Date() br/);out.flush();} }CheckOrder.javapackage testAsyncServlet;import java.io.PrintWriter;
import java.util.Date;import javax.servlet.AsyncContext;public class CheckOrder implements Runnable {private AsyncContext ctx null;public CheckOrder(AsyncContext ctx) {this.ctx ctx;}public void run() {try {// 模拟开通等待Thread.sleep(10000);PrintWriter out ctx.getResponse().getWriter();out.println(已经有权限了lets go! : new Date());out.flush();ctx.complete();} catch (Exception e) {e.printStackTrace();}}
}web.xml?xml version1.0 encodingUTF-8?
web-app xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlnshttp://java.sun.com/xml/ns/javaee xsi:schemaLocationhttp://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd idWebApp_ID version3.0display-nametestAsyncServlet/display-namewelcome-file-listwelcome-fileindex.jsp/welcome-file/welcome-file-listservletservlet-nameasyncServle/servlet-nameservlet-classtestAsyncServlet.AsyncServlet/servlet-classasync-supportedtrue/async-supported/servletservlet-mappingservlet-nameasyncServle/servlet-nameurl-pattern/asyncServlet/url-pattern/servlet-mapping/web-app