0
我想在Java中的doPost方法結束之前獲取HTTP狀態代碼。例如在Python中有self.send_response(200)
,它以異步方式發送狀態?以異步方式獲取HTTP狀態代碼
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*
*/
@SuppressWarnings("unchecked")
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//Final result object
//I want to send a http status code 200 before the task running
myThreadPool = Executors.newFixedThreadPool(2);
Future taskOne = myThreadPool.submit(new Runnable() {
@Override
public void run() {
try {
try {
// My first task
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
// Task two
.
.
莫非你到目前爲止向我們展示你的代碼,並告訴你正在使用哪個框架? – Erik
你的問題確實不清楚。你想異步檢索一個int? http://docs.oracle.com/javaee/7/api/javax/servlet/http/HttpServletResponse.html#getStatus-- – Taylor
您好@Taylor,我希望我的API以異步方式工作,所以,首先,我會發送我的請求並且服務器應該以一個http代碼200響應,並且在後臺繼續執行我的doPost,並且在所有任務完成後它將發送響應。 – user3773203