確保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 –