Java ExtJS处理将PDF保存为StreamingOutput的响应
我正在使用extJS 4.2.1,我想显示一个PDF文件,该文件作为StreamingOutput对象存储在ResponseBuilder中。当响应返回到extjs控制器时,我不知道如何处理它以便在新页面上显示PDFJava ExtJS处理将PDF保存为StreamingOutput的响应,java,ajax,extjs,response,Java,Ajax,Extjs,Response,我正在使用extJS 4.2.1,我想显示一个PDF文件,该文件作为StreamingOutput对象存储在ResponseBuilder中。当响应返回到extjs控制器时,我不知道如何处理它以便在新页面上显示PDF @GET @Path("/images/{imageNumber}/{imageType}") @Produces({"application/pdf"}) public Response openDocument(@PathParam("company") String comp
@GET
@Path("/images/{imageNumber}/{imageType}")
@Produces({"application/pdf"})
public Response openDocument(@PathParam("company") String company,
@PathParam("imageNumber") String imageNumber, @PathParam("imageType") String imageType){
final File imageFile = new File("/someRemoteDir/28717484.pdf");
StreamingOutput stream = new StreamingOutput() {
public void write(OutputStream output) throws IOException, WebApplicationException {
try {
InputStream input = new FileInputStream(imageFile);
byte[] buf = new byte[8192];
int c = 0;
while ((c = input.read(buf, 0, buf.length)) > 0) {
output.write(buf, 0, c);
output.flush();
}
output.close();
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
};
ResponseBuilder response = Response.ok(stream);
response.type("application/pdf");
response.status(200);
response.header("Accept-Ranges","bytes");
response.header("Cache-Control",null);
response.header("Pragma",null);
response.header("Content-Disposition","inline; filename=\"" + imageDoc.getNumber() +"\"");
return response.build();
}
extJS控制器
Ext.Ajax.request({
method: 'GET',
url: CTrack.Config.appPath('loads/images/' + imageNumber + '/' + imageType),
jsonSubmit: true,
success: function(response, opt) {
if (response.status == 200) {
NOT SURE WHAT TO DO HERE?.........
} else {
me.displayError(errorMsg);
} },
failure: function(response, opt) {
console.log('Failure');
}
…我不确定你真的能做到这一点。我只需要一个iframe,并将src设置为您在上面定义的URL。