Tôi đang thực hiện yêu cầu HTTP POST từ GWT Client đến HTTPServlet. Servlet này đang tạo một tệp PDF từ nội dung yêu cầu và ghi nó vào luồng phản hồi.Xử lý tệp đính kèm để phản hồi với RequestBuilder trong GWT
Headers của dòng phản ứng là:
Content-Disposition: attachment; filename=report.pdf
Tôi muốn mở PDF này ở cửa sổ mới của trình duyệt của người dùng hoặc nhắc anh ta tải nó.
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
}
Tôi nên xử lý phản hồi trong onResponseRecieved như thế nào?