2010-05-05 77 views
3

我有一个示例项目StockWatcher使用requestbuilder与servlet(this example)进行通信。我想让servlet异步。我加入以下行doGet方法:GWT requestbuilder与异步servlet 3.0

final AsyncContext ac = request.startAsync(); 
ac.setTimeout(1 * 60 * 1000); 
ac.addListener(new AsyncListener() { 

@Override 
public void onError(AsyncEvent arg0) throws IOException { 
      System.out.println("onError");  
} 

public void onComplete(AsyncEvent event) throws IOException { 
      System.out.println("onComplete"); 
      queue.remove(ac); 
} 

public void onTimeout(AsyncEvent event) throws IOException { 
      System.out.println("onTimeout"); 
      queue.remove(ac); 
} 

@Override 
public void onStartAsync(AsyncEvent arg0) throws IOException { 
      System.out.println("onStartAsync"); 

} 
}); 
queue.add(ac); 

加入异步注释:@WebServlet(asyncSupported=true) ,并改变了doGet方法的其余部分:

PrintWriter out = ac.getResponse().getWriter(); 
out.println("Something"); 
out.flush(); 

现在没有什么返回。我错了什么?必须改变客户端的东西? Glassfish 3不显示任何错误。

+0

你为什么要做queue.add(ac);两次? – 2010-05-05 12:12:47

+0

对,我的错。但它不能解决我的问题 – Mike 2010-05-05 12:24:43

回答