u010250554 2016-01-08 07:01 采纳率: 0%
浏览 2726

javaweb如何查看上传的pdf文件

我的在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()

  • 写回答

2条回答 默认 最新

  • GrowingDarker 2016-01-08 07:07
    关注

    showDesignFile 。。。。action里的方法名不能有参数的。 把你的public void showDesignFile(String fileName) 改成
    public void showDesignFile() 。把你要传入的 参数声明成变量啊, 在action 里面这么写,private String filename; 然后给这个变量设置set方法就行了啊。

    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料