How do we upload files

本文介绍了如何使用Struts2框架进行文件上传操作,包括利用MultipartRequestWrapper和fileUpload拦截器的方法。此外还详细说明了如何处理多个文件上传及配置相关属性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

xml 代码
  1. How do we upload files   
  2.  Edit Page    Browse Space    Add Page    Add News    
  3. Added by tm_jee, last edited by Ted Husted on Jan 28, 2007  (view change)    
  4. You can obtain the MultipartRequestWrapper from the ServletActionContext or by utilizing the fileUpload interceptor. The fileUpload interceptor is preferred.   
  5.   
  6. Ask the ServletActionContext   
  7. MultipartRequestWrapper multipartRequest = ((MultipartRequestWrapper)ServletActionContext.getRequest())   
  8. The MultipartRequestWrapper provideds access methods such as getFiles, getFile, getContentType, hasErrors, getErrors, and so forth, so that you can process the file uploaded.   
  9.   
  10. Utilize the fileUpload Interceptor   
  11.  _Preferred_   
  12.   
  13. Ensure that {{fileUpload }} Interceptor is included in the Action's stack.    
  14.  The default stack already includes {{fileUpload }}.    
  15. Ensure that the HTML form sets the enctype and specifies on or more file type inputs.    
  16. <form name="myForm" enctype="multipart/form-data">  
  17.      <input type="file" name="myDoc" value="Browse ..." />  
  18.      <input type="submit" />  
  19.   </form>  
  20. Ensure that the Action provides one or more fileUpload mutator methods, with names that correspond to name of the file type input.    
  21. public void setMyDoc(File myDoc)   
  22. public void setMyDocContentType(String contentType)   
  23. public void setMyDocFileName(String filename)   
  24. The Action may also provide the corresponding accessor methods.    
  25. public File getMyDoc()   
  26. public ContentType getMyDocContentType()   
  27. public String getMyDocFileName()   
  28. Handling multiple files   
  29. When multiple files are uploaded by a form, the files are represented by an array.   
  30.   
  31. Given:   
  32.   
  33. <form name="myForm" enctype="multipart/form-data">  
  34.       <input type="file" name="myDoc" value="Browse File A ..." />  
  35.       <input type="file" name="myDoc" value="Browse File B ..." />  
  36.       <input type="file" name="myDoc" value="Browse File C ..." />  
  37.       <input type="submit" />  
  38.    </form>  
  39. The Action class can define file handling methods that accept an array.   
  40.   
  41. public void setMyDoc(File[] myDocs)   
  42. public void setMyDocContentType(String[] contentTypes)   
  43. public void setMyDocFileName(String[] fileNames)   
  44. The uploaded files can be handled by iterating through the appropriate array.   
  45.   
  46. Extra Information   
  47. Property  Default     
  48. struts.multipart.parser  Commons FileUpload     
  49. struts.multipart.saveDir  javax.servlet.context.tempdir as defined by container     
  50. struts.multipart.maxSize  Approximately 2M     
  51.   
  52. @see struts.properties   
  53. @see org.apache.struts2.dispatcher.FilterDispatcher#doFilter(SerlvetRequest, ServletRepsonse, FilterChain)   
  54. @see org.apache.struts2.dispatcher.DispatcherUtil#wrapRequest(HttpServletRequest, SerlvetContext)   
  55. @see org.apache.struts2.dispatcher.multipart.MultipartRequestWrapper   
  56. @see org.apache.struts2.interceptor.FileUploadInterceptor   
  57.   
资源下载链接为: https://pan.quark.cn/s/502b0f9d0e26 计算机体系结构是计算机科学与技术领域极为关键的课程,它聚焦于硬件与软件的交互以及计算系统设计优化的诸多方面。国防科技大学作为国内顶尖工科院校,其计算机体系结构课程备受瞩目。本课件汇集了该课程的核心内容,致力于助力学生深入探究计算机工作原理。 课件内容主要涵盖以下要点:其一,计算机基本组成,像处理器(CPU)、内存、输入/输出设备等,它们是计算机硬件系统基石,明晰其功能与工作模式对理解计算机整体运行极为关键。其二,指令集体系结构,涵盖不同指令类型,如数据处理、控制转移指令等的执行方式,以及 RISC 和 CISC 架构的差异与优劣。其三,处理器设计,深入微架构设计,如流水线、超标量、多核等技术,这些是现代处理器提升性能的核心手段。其四,存储层次结构,从高速缓存到主内存再到外部存储器,探究存储层次缘由、工作原理及数据访问速度优化方法。其五,总线和 I/O 系统,学习总线协议,了解数据、地址、控制信号在组件间传输方式,以及 I/O 设备分类与交互方式,如中断、DMA 等。其六,虚拟化技术,讲解如何利用虚拟化技术使多个操作系统在同硬件平台并行运行,涉及虚拟机、容器等概念。其七,计算机网络与通信,虽非计算机体系结构主体,但会涉及计算机间通信方式,像 TCP/IP 协议栈、网络接口卡工作原理等。其八,计算机安全与可靠性,探讨硬件层面安全问题,如物理攻击、恶意硬件等及相应防御举措。其九,计算机体系优化,分析性能评估指标,如时钟周期、吞吐量、延迟等,学习架构优化提升系统性能方法。其十,课程习题与题库,通过实际题目训练巩固理论知识,加深对计算机体系结构理解。 国防科大该课程不仅理论扎实,还可能含实践环节,让学生借助实验模拟或真实硬件操作深化理解。课件习题集为学习者提供丰富练习机会,助力掌握课程内容。共享
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值