我的在js中做了一个超链接:
colDataManage.formatter=function(value,rowData,rowIndex){
var retVal= '查看';
return retVal;
};
具体方法是:
function showDesignFile(id){
if(id!=null&&id!=""){
var rowData = $('#gridtable').datagrid('getSelected');
var designDoc = rowData.designDoc;
if(designDoc==null){
$.messager.alert('提示','不存在该设计文档,无法进行查看!','info');
}else{
window.location.href = path+'/vocDesign/showDesignFile.action?fileName='+encodeURI(encodeURI(designDoc));
}
}else{
$.messager.alert('提示','不存在该设计文档,无法查看!','info');
}
}
action里头是:
public void showDesignFile(String fileName) throws IOException {
String filePath = ServletActionContext.getServletContext().getRealPath("fileupload");
HttpServletResponse response = ServletActionContext.getResponse();
File f = new File(filePath);
if (!f.exists()) {
response.sendError(404, "File not found!");
return;
}
BufferedInputStream br = new BufferedInputStream(new FileInputStream(f));
byte[] bs = new byte[1024];
int len = 0;
response.reset(); // 非常重要
if (true) { // 在线打开方式
URL u = new URL("file:///" + filePath);
String contentType = u.openConnection().getContentType();
response.setContentType(contentType);
response.setHeader("Content-Disposition", "inline;filename="
+ fileName);
// 文件名应该编码成utf-8
} else {
// 纯下载方式
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment;filename="
+ fileName);
}
OutputStream out = response.getOutputStream();
while ((len = br.read(bs)) > 0) {
out.write(bs, 0, len);
}
out.flush();
out.close();
br.close();
}
}
总是进不去方法 还出现500异常:
java.lang.NoSuchMethodException: com.xxx.xxx.action.VocDesignReportAction.showDesignFile()