我正在从GWT客户端向HTTPServlet发出HTTP POST请求.此Servlet正在从请求内容创建PDF文件并将其写入响应流.
响应流的标头是:
Content-Disposition: attachment; filename=report.pdf
Run Code Online (Sandbox Code Playgroud)
我想在用户浏览器的新窗口中打开此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 …Run Code Online (Sandbox Code Playgroud)