public String dowItemCg(String docType){
String type = "";
if(docType.equals("5")){
//若文件类型是5,则是下载绩效评价模板
type = "项目绩效评估报告格式.doc";
}else if(docType.equals("8")){
//若文件类型是8,则是下载项目评审报告模板
type = "项目评审报告.doc";
}else{
type = "templet.rar";
}
String fileName = "\\upload\\templet\\"+type;
try {
inputStream = ServletActionContext.getServletContext().getResourceAsStream(fileName);
} catch (Exception e) {
logger.error("下载附件时,读取文件失败!",e);
super.addActionError("读取文件失败,可能不存在该文件!");
return "error";
}
if(inputStream == null){
super.addActionError("读取文件失败,可能不存在该文件!");
return "error";
}
downloadChineseFileName = type;
try {
downloadChineseFileName = new String(downloadChineseFileName.getBytes(), "ISO8859-1");
}catch(Exception e){
logger.error("转换文件名编码时出错!",e);
}
return "download";
}
调用此方法时,报java.lang.NoSuchMethodException,才发现struts2框架不知带参数的action。果断改成在方法内通过request获取参数值。
String type = "";
if(docType.equals("5")){
//若文件类型是5,则是下载绩效评价模板
type = "项目绩效评估报告格式.doc";
}else if(docType.equals("8")){
//若文件类型是8,则是下载项目评审报告模板
type = "项目评审报告.doc";
}else{
type = "templet.rar";
}
String fileName = "\\upload\\templet\\"+type;
try {
inputStream = ServletActionContext.getServletContext().getResourceAsStream(fileName);
} catch (Exception e) {
logger.error("下载附件时,读取文件失败!",e);
super.addActionError("读取文件失败,可能不存在该文件!");
return "error";
}
if(inputStream == null){
super.addActionError("读取文件失败,可能不存在该文件!");
return "error";
}
downloadChineseFileName = type;
try {
downloadChineseFileName = new String(downloadChineseFileName.getBytes(), "ISO8859-1");
}catch(Exception e){
logger.error("转换文件名编码时出错!",e);
}
return "download";
}
调用此方法时,报java.lang.NoSuchMethodException,才发现struts2框架不知带参数的action。果断改成在方法内通过request获取参数值。