tailieunhanh - Expert Spring MVC and Web Flow phần 4

điều này có nghĩa là lớp cuối cùng trong chuỗi xử lý trước khi các byte được gửi cho khách hàng. Vào thời điểm này, tất cả các logic kinh doanh đã được thực hiện, tất cả các giao dịch được cam kết, và tất cả các nguồn này đã được phát hành. Là cuối cùng, | CHAPTER 5 THE PROCESSING PIPELINE 109 Listing 5-39. MultipartHttpServletRequest Interface package public interface MultipartHttpServletRequest extends HttpServletRequest Iterator getFileNames MultipartFile getFile String name Map getFileMap Before the end of the request life cycle and after the handling code has had a chance to work with the uploaded files the DispatcherServlet will then call cleanupMultipart . This removes any state left behind by the file upload implementation code such as temporary files on the file system. Therefore it is important that any request handling code should work with the uploaded files before request processing finishes. So which library should you use Commons FileUpload or COS The choice is up to you as both have been around for years and are considered stable. However keep in mind that Commons FileUpload will probably receive more maintenance in the future. Of course if neither provides the features you require you may implement a new MultipartResolver. Example Working with file uploads is actually quite simple as most of the mechanisms are handled by the DispatcherServlet and thus hidden from request handling code. For an example we will register a Jakarta Commons FileUpload MultipartResolver and create a Controller that saves uploaded files to a temporary directory. Listing 5-40 contains the configuration required for the CommonsMultipartResolver. Listing 5-40. MultipartResolver Applicationcontext xml version DOCTYPE beans PUBLIC - SPRING DTD BEAN EN http dtd beans bean id multipartResolver class property name maxUploadSize value 2000000 bean bean name handleUpload class property name tempDirectory value tmp 110 CHAPTER 5 THE PROCESSING PIPELINE bean beans Note that we declared the multipart resolver in the same Applicationcontext

TỪ KHÓA LIÊN QUAN