确保struts过滤器允许异步。下面是在web.xml文件中的样子:
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
<async-supported>true</async-supported>
</filter>
然后从内行动取得HttpServletRequest
和HttpServletResponse
和使用AsyncContext
你将一个servlet中:
public String execute() {
HttpServletRequest req = ServletActionContext.getRequest();
HttpServletResponse res = ServletActionContext.getResponse();
final AsyncContext asyncContext = req.startAsync(req, res);
asyncContext.start(new Runnable() {
@Override
public void run() {
try {
// doing some work asynchronously ...
}
finally {
asyncContext.complete();
}
}
});
return Action.SUCCESS;
}
检查此[链接] [1]。它可以帮助你 [1]:http://stackoverflow.com/questions/11026542/get-json-data-from-struts/13527598#13527598 –