Ajax PDF下载无法使用ext js
我不熟悉Ajax PDF下载无法使用ext js,ajax,spring-mvc,pdf,extjs,Ajax,Spring Mvc,Pdf,Extjs,我不熟悉Extjs。我试图通过单击网格表pdf列中的pdf链接从服务器下载pdf文件,但无法下载该文件。请帮我解决这个问题 请在下面找到我的代码片段 PDF专栏 AJAX调用 事件URI 服务器端代码 public@ResponseBody 地图下载PDF(HttpServletRequest请求, HttpServletResponse,@RequestParam字符串docUri){ CheckOutDocumentResult out=null; 试一试{ out=eDashService
Extjs
。我试图通过单击网格表pdf
列中的pdf链接从服务器下载pdf文件,但无法下载该文件。请帮我解决这个问题
请在下面找到我的代码片段
PDF专栏
AJAX调用
事件URI
服务器端代码
public@ResponseBody
地图下载PDF(HttpServletRequest请求,
HttpServletResponse,@RequestParam字符串docUri){
CheckOutDocumentResult out=null;
试一试{
out=eDashService.getDocument(docUri);
字符串ext=out.getDocumentFileExtension();
字符串fname=out.getDocumentFileName();
if(ext!=null&&ext.toLowerCase().equals(“pdf”)){
response.setContentType(“APPLICATION/pdf”);
字符串标题set=“附件;文件名=\”“+fname+”\”;
response.setHeader(“内容处置”、“附件;文件名=\”)
+fname+“\”;”;
InputStream is=new ByteArrayInputStream(out.getFileData());
BufferedInputStream bis=新的BufferedInputStream(is);
OutputStream responseOutputStream=response.getOutputStream();
整数字节;
而((bytes=bis.read())!=-1){
responseOutputStream.write(字节);
}
}
}捕获(例外e){
e、 printStackTrace();
}
if(out.getDocumentFileName().equals(“null”)){
返回geteDashMapError(out.getErrorMessage());
}否则{
返回geteDashMapStatus(“无错误”);
}
}
我在这里做错了什么?不要请求Ajax下载文件。 单击您的链接“执行标准提交”请求文件时,我在尝试下载Excel文件时遇到了问题 修复了标准提交的问题 下面是一个关于通过Ajax请求下载文件的线程
致以最诚挚的问候。请您更好地描述一下无法下载的内容。当你直接访问url时,你能下载吗?在我的应用程序中,我们有一列名为
PDF
,在该列中,我们每行有PDF链接,这意味着我们可以在单击PDF链接时以PDF格式下载数据。但在我的情况下,当我点击PDF链接时,该操作无法执行…但我可以下载excel文件,但不能下载PDF。我发现了问题所在。问题在于调用webservice签出文档时。我正在尝试解决这个问题。我想您是将Excel文件下载为xml格式,然后将其写入Excel?
{
header: "PDF",
align: 'center',
width: 35,
renderer: function (value, metaData, record, rowIndex, colIndex, store) {
if(record.get("extension") == "pdf") {
metaData.style = 'text-decoration:underline;';
metaData.tdAttr = 'data-qtip="' + record.get("eventURI") + '"';
return 'PDF';
}
else
return '';
}
}
if (colName == 'PDF' && currentRow.get('extension')=="pdf") {
if (!Ext.fly('fsfrmDummy')) {
var frm = document.createElement('form');
frm.id = 'fsfrmDummy';
frm.name = 'fsfrmDummy';
frm.className = 'x-hidden';
document.body.appendChild(frm);
}
Ext.Ajax.request({
method: 'post',
url: 'edash/downloadDoc.action',
params: {docUri: currentRow.get('eventURI')},
success: function (response, config) {
},
failure: function (response, config) {
appException('ERROR', response.message,
Ext.MessageBox.ERROR,
Ext.Msg.OK);
},
form: Ext.fly('fsfrmDummy'),
isUpload: true
});
}
{
header: "EVENT_URI",
width: 95,
sortable: true,
dataIndex: 'eventURI',
renderer: function (value, metaData,record, rowIndex, colIndex, store) {
if(record.get("extension") == "pdf") {
metaData.style = 'text-decoration:underline;';
}
return value;
}
}
public @ResponseBody
Map<String, ? extends Object> downloadPDF(HttpServletRequest request,
HttpServletResponse response, @RequestParam String docUri) {
CheckOutDocumentResult out = null;
try {
out = eDashService.getDocument(docUri);
String ext = out.getDocumentFileExtension();
String fname = out.getDocumentFileName();
if (ext != null && ext.toLowerCase().equals("pdf")) {
response.setContentType("APPLICATION/pdf");
String headerSetting = "attachment; filename=\"" + fname + "\";";
response.setHeader("Content-Disposition", "attachment; filename=\""
+ fname + "\";");
InputStream is = new ByteArrayInputStream(out.getFileData());
BufferedInputStream bis = new BufferedInputStream(is);
OutputStream responseOutputStream = response.getOutputStream();
int bytes;
while ((bytes = bis.read()) != -1) {
responseOutputStream.write(bytes);
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (out.getDocumentFileName().equals("null")) {
return geteDashMapError(out.getErrorMessage());
}else{
return geteDashMapStatus("no errors");
}
}