学习札记--Struts1 文件上传
来源:互联网 发布:q币赚钱软件 编辑:程序博客网 时间:2024/05/01 02:48
public class MyFileUpload extends Action {@Overridepublic ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {ActionForward forward = mapping.findForward("success");String targetPath = request.getSession().getServletContext().getRealPath("/upload");String uploadSuccessFileName = "";if(ServletFileUpload.isMultipartContent(request)){System.out.println("this is a multipart form");ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());List<FileItem> files = upload.parseRequest(request); File targetFile = null; if(files != null && files.size() > 0)for(FileItem file : files){System.out.println(file.getName() + "upload start. Field Name:"+file.getFieldName());try{ targetFile = new File(targetPath+"/"+file.getName()); file.write(targetFile); uploadSuccessFileName += file.getName() + " ";}catch(Exception ioe){ioe.printStackTrace();continue;} }}request.setAttribute("fileName", uploadSuccessFileName);return forward;}}
其实算不上是struts1了 而是common-fileupload包。这里我用的是1.2.2版本,依赖common-io包。
上边红色代码,可能根据不同服务器稍有不同,这里是tomcat。
weblogic写法request.getSession().getServletContext().getResource("/").getPath()
- 学习札记--Struts1 文件上传
- 学习札记--Struts1 文件上传2
- 学习札记--Struts1 配置文件
- struts1.2文件上传
- Struts1文件上传
- Struts1.2.9文件上传
- struts1 ftp 文件上传
- struts1文件上传
- struts1中的文件上传
- Struts1 上传文件
- Struts1文件上传
- Struts1文件上传
- struts1多文件上传
- struts1 上传文件
- Struts1上传文件
- struts1.2上传文件
- struts1 实现 文件上传
- struts1(3)----文件上传
- 如何在调用WCF服务之前弹出一个确认对话框?
- js一百零一夜之第二夜-js获取外部css样式
- 最近看到或是总结的一些观点
- HOJ 1496 World Cup Noise
- 《代码大全》读书笔记三
- 学习札记--Struts1 文件上传
- Android调用系统分享功能以及createChooser的使用
- HOJ 1459 Goldbach's Conjecture
- 对我启示的几句话
- Project Euler 45
- C#字符串相关函数(持续更新,绝不TJ)
- TCP大并发短连接造成TIME_WAIT问题解决办法
- 什么是回调函数
- spring源码阅读之IOC2 欢迎点评参考