struts 1 中的文件上传 Action中的部分代码
来源:互联网 发布:深入浅出html5编程 编辑:程序博客网 时间:2024/05/02 13:19
/**
* 上传文件
*/
public ActionForward upload(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
UploadFileForm formBean = (UploadFileForm) form;
//JavaBean
UploadFile file = new UploadFile();
if (formBean.getUploadfile() != null && formBean.getUploadfile().getFileSize() > 0) {
//根据当前日期设置上传目录
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd/");
String pathdir = "images/uploadfile/" + dateFormat.format(new Date());
//得到服务器上的实际目录
String realpathdir = request.getSession().getServletContext().getRealPath(pathdir);
File savedir = new File(realpathdir);
//如果目录不存在,则新建
if (!savedir.exists()) {
savedir.mkdirs();
}
//获取上传文件的扩展名
String ext = formBean.getUploadfile().getFileName().substring(
formBean.getUploadfile().getFileName().lastIndexOf("."));
//用UUID产生文件名
String filename = UUID.randomUUID() + ext;
//生成一个文件输出流,将文件写到指定的目录中
FileOutputStream fileOutputStream = new FileOutputStream(new File(savedir, filename));
fileOutputStream.write(formBean.getUploadfile().getFileData());
fileOutputStream.close();
//将文件路径保存到数据库
String filepath = pathdir + filename;
file.setFilepath(filepath);
uploadFileService.save(file);
request.setAttribute("message", "文件上传成功!");
request.setAttribute("urladdress", SiteUrl.readUrl("control.brand.list"));
}
}
- struts 1 中的文件上传 Action中的部分代码
- struts中的文件上传
- Struts中的文件上传
- Struts 中的文件上传[转贴]
- struts中的文件上传解决
- struts 2 中的文件上传
- struts 中的图片文件上传
- 用代码说明Struts 1.0中的action
- Struts中的Action方法
- Struts中的action
- struts中的action类
- struts.xml文件中的action元素中的属性及其作用
- struts 1 中的DispatchAction-【分派action】
- struts中的上传问题
- struts中action中的种类
- struts中的各种action类
- struts中action中的函数
- struts中的action是单态的
- 每个项目中,你不得不知的11个Java第三方类库
- 谷歌证实收购网络电话软件开发商Gizmo5
- CodeTyphon--------“Pascal编程平台 ”-----北京0665鼎多xj提供
- 我不要钱,我只要吃饭,我两天没有吃饭了
- java读取txt文本
- struts 1 中的文件上传 Action中的部分代码
- 每次关机都会出现内存不能为writen的对话框,怎么解决?
- 代码编写中关于文件/函数注释的统一格式
- 魔兽争霸3的MapHack制作教程(一)显示敌对单位
- hibernate.hbm2ddl.auto配置详解
- java读取 excel 文本
- 用AutoCAD调用自定义类库
- 南京的第一场雪,看我堆得雪人
- 魔兽争霸3的MapHack制作教程(二)去除战争迷雾