我正在从GWT客户端向HTTPServlet发出HTTP POST请求。这个Servlet会从请求内容中创建一个PDF文件并将其写入响应流中。
响应流的头如下:
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
}
我应该如何处理onResponseReceived回调中的响应?