|
楼主 |
发表于 2007-4-6 14:05
|
显示全部楼层
SPRING 中也有支持文件上传的接口,还有jspsmart,commons-fileupload。。。。
Spring支持的文件上传的接口和实现都在org.springframework.web.multipart ,org.springframework.web.multipart.commons, org.springframework.web.multipart.cos ,org.springframework.web.multipart.support
几个包里边。分别来看看几个包到底有什么。
1.org.springframework.web.multipart包括有MultipartFile ,MultipartHttpServletRequest ,MultipartResolver三个接口,很明显multipart提供了最基本的文件上传的接口。每个接口各有什么方法呢?
1.1.MultipartFile
看api说明
public interface MultipartFile
A representation of an uploaded file received in a multipart request.
The file contents are either stored in memory or temporarily on disk. In either case, the user is responsible for copying file contents to a session-level or persistent store as and if desired. The temporary storages will be cleared at the end of request processing.
方法有:
getBytes()
Return the contents of the file as an array of bytes.
getContentType()
Return the content type of the file.
getInputStream()
Return an InputStream to read the contents of the file from.
getName()
Return the name of the parameter in the multipart form.
getOriginalFilename()
Return the original filename in the client's filesystem.
getSize()
Return the size of the file in bytes.
isEmpty()
Return whether the uploaded file is empty, that is, either no file has been chosen in the multipart form or the chosen file has no content.
transferTo(File dest)
Transfer the received file to the given destination file.
1.2.MultipartHttpServletRequest 接口,实现类有AbstractMultipartHttpServletRequest, CosMultipartHttpServletRequest, DefaultMultipartHttpServletRequest, MockMultipartHttpServletRequest 四个。
public interface MultipartHttpServletRequest
extends HttpServletRequest
Provides additional methods for dealing with multipart content within a servlet request, allowing to access uploaded files. Implementations also need to override the standard ServletRequest methods for parameter access, making multipart parameters available.
看到名字和看到它继承了 HttpServletRequest,大家应该大概猜到它的作用了吧。
具体的方法有:
getFile(String name)
Return the contents plus description of an uploaded file in this request, or null if it does not exist.
getFileMap()
Return a Map of the multipart files contained in this request
getFileNames()
Return an Iterator of String objects containing the parameter names of the multipart files contained in this request.
1.3.MultipartResolver 接口,实现类有CommonsMultipartResolver, CosMultipartResolver 两个
[ 本帖最后由 hexq 于 2007-4-6 14:32 编辑 ] |
|