我正在從GWT客戶端向HTTPServlet發送HTTP POST請求。此Servlet從請求內容創建PDF文件並將其寫入響應流。響應流的GWT中的RequestBuilder處理附件
標題有:
Content-Disposition: attachment; filename=report.pdf
我想打開這個PDF在用戶的瀏覽器的新窗口或提示他下載。
import com.google.gwt.http.client.*;
...
String url = "http://www.myserver.com/getData?type=3";
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(url));
try {
Request request = builder.sendRequest(data, new RequestCallback() {
public void onError(Request request, Throwable exception) {
// Couldn't connect to server (could be timeout, SOP violation, etc.)
}
public void onResponseReceived(Request request, Response response) {
if (200 == response.getStatusCode()) {
// Process the response in response.getText()
// Window.open(url, "_blank", "");
} else {
// Handle the error. Can get the status text from response.getStatusText()
}
}
});
} catch (RequestException e) {
// Couldn't connect to server
}
我應該如何處理onResponseRecieved中的響應?