清秋扶摇

导航

文件类型判断

 

if(upload==null){
mess = new Message();
mess.setTitle("操作失败");
mess.setContent("文件类型非法,请选择.xls文件类型!");
mess.setLink("billManage_plinit.do");
return "message";
}

public void setUploadFileName(String uploadFileName) {
// System.out.println("set_uploadFilename="+this.uploadFileName);
String filetype = uploadFileName.substring(uploadFileName.lastIndexOf(".") + 1, uploadFileName.length());
try {
if (filetype.length() > 0) {
List<String> typeList = new ArrayList<String>(Arrays.asList("docx", "doc", "xls", "xlsx", "ppt", "pptx",
"pdf", "jpg", "jpeg", "bmp", "gif", "png", "pdf", "txt", "rar", "wps", "zip"));
if (!typeList.contains(filetype.toLowerCase())) {
throw new Exception("文件类型非法,请选择正确的文件类型!");
}
} else {
throw new Exception("文件类型非法,请选择正确的文件类型!");
}
} catch (Exception e) {
e.printStackTrace();
return;
}
this.uploadFileName = uploadFileName;
}

posted on 2019-03-25 16:25  一拾三夏  阅读(331)  评论(0编辑  收藏  举报