Teach you how to use WEBWORK to upload files.

  
Everyone knows that webwork is simple, flexible and powerful. It is a standard Command pattern framework implementation, and completely separate from the web layer, dedicated to componentization and code reuse J2EE Web framework, But you don't know another good thing about it, that is, you can also use WEBWORK to achieve file uploading. Here is how to use WEBWORK to implement file uploading method.
Webwork uses ognl to implement data binding. Very useful function, can avoid cumbersome call request.getParameter, object setter, do not need any redundant configuration files, plus the function of the converter, we can use a business object, from the front desk to the background, again You don't need to consider String conversion, you don't need DTO, you don't need FormBean.
You can use the data uploading to upload the common upload files on the web application, then it is perfect: action no longer need to know any web information. , need to operate on a specific Object, call getObject, need to operate on the file uploaded by the user, adjust getFile.
Before webwork2.1.5, there is a detailed introduction to this problem. After 2.1.5, this interceptor was added to the official release version: com.opensymphony.webwork.interceptor.FileUploadInterceptor
First come Take a look at our Action:



We can see that this Action is quite simple. Just define a File type property and setter, we can use this File object to do anything.< There is no difference between the page and the normal upload page:


It is necessary to pay attention to the name of the field and the same name of the action. The rest is to configure the interceptor:
Copyright © Windows knowledge All Rights Reserved