您的位置:首页 > 其它

巴巴运动网学习笔记(46-50)

2012-04-10 17:10 330 查看
实现文件上传模块
1.完成文件上传模块的实体bean和业务bean()

View Code

private static Properties pro = new Properties();
static{
try {
pro.load(BaseForm.class.getClassLoader().getResourceAsStream("validateType.properties"));
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 验证文件格式是否合法
* @param image
* @return
*/
public boolean isFileTypeValidate(FormFile file){
if(file!=null&&file.getFileSize()>0){
String ext = file.getFileName().substring(file.getFileName().lastIndexOf('.')+1);
List<String> allowType = new ArrayList<String>();
for(Object key : pro.keySet()){
String value = (String)pro.get(key);
String[] valueArr = value.split(",");
for(int i=0;i<valueArr.length;i++){
allowType.add(valueArr[i]);
}
}
return allowType.contains(file.getContentType())&&pro.keySet().contains(ext);
}
return false;
}


5.修改文件上传成功之后的消息页面(文件上传成功之后采用跳转的方式跳转到其他页面)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: