STRUTS2 because license reason long ago no longer support COS upload, specifically see http://struts.apache.org/2.1.6/docs/file-upload.html official note:
there is a third alternative, COS, but it is removed due to licensing incompatibilities.
Currently, Commons-fileupload is embedded and supported by plugin mode Pell. But Struts.properties is still not updated, and the articles on the web also remain by modifying the struts.multipart.parser corresponding values for the Cos to come from the dynamic support Cos.
Let's not consider the license factor and see how STRUTS2 can support cos:
1) Create a class that implements Org.apache.struts2.dispatcher.multipart.MultiPartRequest excuses
Java code
- /**
- * @author <a href= "http://intolong.spaces.live.com/" >Jalen</a>
- */
- Public class Cosmultipartrequest implements Multipartrequest {
- private Multipartrequest Multi;
- private String defaultencoding;
- private Boolean maxsizeprovided;
- private int maxSize;
- @Inject (strutsconstants.struts_i18n_encoding)
- public void setdefaultencoding (String defaultencoding) {
- this.defaultencoding = defaultencoding;
- }
- @Inject (strutsconstants.struts_multipart_maxsize)
- public void Setmaxsize (String maxSize) {
- this.maxsizeprovided = true;
- this.maxsize = Integer.parseint (maxSize);
- }
- @Override
- Public string[] getContentType (String fieldName) {
- return new string[] {Multi.getcontenttype (fieldName)};
- }
- @SuppressWarnings ("unchecked")
- @Override
- Public List geterrors () {
- return collections.empty_list;
- }
- @Override
- Public file[] GetFile (String fieldName) {
- return new file[] {multi.getfile (fieldName)};
- }
- @Override
- Public string[] GetFileNames (String fieldName) {
- return new string[] {multi.getfile (fieldName). GetName ()};
- }
- @SuppressWarnings ("unchecked")
- @Override
- Public enumeration<string> Getfileparameternames () {
- return Multi.getfilenames ();
- }
- @Override
- Public string[] Getfilesystemname (String name) {
- return new string[] {multi.getfilesystemname (name)};
- }
- @Override
- Public string GetParameter (string name) {
- return Multi.getparameter (name);
- }
- @SuppressWarnings ("unchecked")
- @Override
- Public enumeration<string> Getparameternames () {
- return Multi.getparameternames ();
- }
- @Override
- Public string[] Getparametervalues (String name) {
- return multi.getparametervalues (name);
- }
- @Override
- public Void Parse (httpservletrequest request, String Savedir) throws IOException {
- if (maxsizeprovided) {
- Multi = new Multipartrequest (Request, Savedir, maxSize, defaultencoding);
- } Else {
- Multi = new Multipartrequest (Request, Savedir, defaultencoding);
- }
- }
- }
2) Modify the Struts.xml to specify your parser
Java code
- <constant name="Struts.multipart.parser" value="cos"/>
This can also be done by modifying the struts.properties to the same effect.
3) Modify Struts.xml, register your parser
Java code
- <bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest" name="cos" class=" Jalen.core.struts2.CosMultiPartRequest "/>
Done.
Following the performance comparison of a Cos and other upload lib, I did not test myself:
Processing HTTP-based file uploads, there are so few opensource Lib,o ' Reilly Cos,apache FileUpload, and Jspsmart's smartupload.
On-line check their performance comparison, excerpt as follows:
Using 2M, 20M, 45M, 200M upload size to test the time spent in three components (in MS) results are:
2M
536
|
1th time |
2nd time |
3rd time |
4th time |
Average |
Cos |
297 |
203 |
234 |
245 |
245 |
FileUpload |
281 |
312 |
281 |
31 2 |
297 |
smartupload |
< p>531 |
594 |
485 |
532 |
20M
|
1th time |
2nd time |
3rd time |
4th time |
Average |
Cos |
2562 |
2109 |
2719 |
2172 |
2391 |
FileUpload |
4062 |
4140 |
536 0 |
3922 |
4371 |
Smar Tupload |
3453 |
3094 |
3078 |
3547 |
3293 |
45M
|
1th time |
2nd time |
3rd time |
4th time |
Average |
Cos |
4860 |
4844 |
5125 |
5171 |
9 |
FileUpload |
9000 |
8391 |
10375 |
10078 |
9461 |
Smart Upload |
8265 |
9187 |
8672 |
8856 |
8745 |
200M
|
1th time |
2nd time |
3rd time |
4th time |
Average |
Cos |
55813 |
52282 |
54796 |
51187 |
53520 |
FileUpload |
76343 |
68531 |
80954 |
79031 |
76215 |
Smartupload |
Memory Stack Overflow |
|
|
|
|
From the above table comparison, we can see that Cos always maintains good performance. When the upload volume is small (capacity <2m, which is the most common case), COS is not much better than fileupload performance, but Smartupload has begun to show weakness. As the capacity increases, fileupload and smartupload performance drops very fast, until the 200M capacity, Smartupload has been overwhelmed by the crash, and Cos at this time spent less than fileupload more than 20 seconds, cannot but say in this evaluation , Cos has the highest performance.
Struts2 integrated cos (RPM)