传统Servlet应用

编程

@SpringBootApplication

@ServletComponentScan(basePackages = "com.jackhu.diveinspringboot.web.servlet")

public class Application {

public static void main(String[] args) {

SpringApplication.run(Application.class, args);

}

}

输出结果

2、异步Servlet 组件

 

protected void doGet(HttpServletRequest req, HttpServletResponse resp)

throws ServletException, IOException {

AsyncContext asyncContext = req.getAsyncContext();

asyncContext.start(() -> {

try {

resp.getWriter().print("hello hll");

} catch (IOException e) {

e.printStackTrace();

}

});

// 触发完成

asyncContext.complete();

}

提示错误:

 

原因:

@WebServlet默认不支持异步,需要手动开启

/**

* @return asynchronous operation supported by this Servlet

*/

boolean asyncSupported() default false;

修改 asyncSupported = true

@WebServlet(urlPatterns = "/my/servlet",

asyncSupported = true)

以上是 传统Servlet应用 的全部内容, 来源链接: utcz.com/z/513092.html

回到顶部