4) Target All Uploads to one Location. |
Xload has easy to use facilities to allow you to target all uploads to one specific location either within the scope of one single request or within the scope of a whole web application.
The XloadManager class provides two different families of methods which are overloaded to achieve this.
1. targetAll(): This family of methods allow you to, in one statement, target every file upload to one location irrespective of how many file parameters exist in the request. Using this method all file parameters that exist in the request are targeted to the location specified. This method can be called numerous times to provide multiple locations for all file uploads. These methods exist solely within the scope of a single request.
IMPORTANT:- The targetAll() methods would typically be used to provide a simple way to specify a location for all file uploads inside a request OR they could be used to specify a location for an unknown set of uploads (file parameters) that the user of the application dynamically creates, per request. |
The code below demonstrates simple usage of this facility which targets all uploads within a particular request to the directory uploaded:
XloadManager xman = new XloadManager(request); xman.targetAll("file1", "uploaded");
|
2. targetEverything(): This family of methods allow you to do exactly the same as the targetAll() family of methods except that these methods exist within the scope of a whole web application. What this effectively means is that when you call one of these methods then that target will exist for every instance of XloadManager that is created within one web application (or more accurately within the scope of the class loader that loaded the XloadManager class as these targets are held statically).
IMPORTANT:- The targetEverything() methods would typically be used to provide a simple way to specify a location for all file uploads for a web application OR they could be used to specify a location for unknown uploads (file parameters) that the user of the application dynamically creates, for the whole application. |
IMPORTANT:- Because the scope of the targetEverything() methods is web application wide you must be careful where you call these methods. For example if you call these methods inside a servlets init() method then every time a servlet is instantiated, a new target will be set. It is best to call these methods inside static code and probably in an application scope JavaBean or similar location. |
The code below demonstrates simple usage of this facility which targets all uploads for a web application to the directory uploaded:
XloadManager.targetEverything("file1", "uploaded");
|
Actual creation of the targets for all these methods occurs just before the files are uploaded which is called JITT (Just In Time Targeting). This means that they will be added to the target list just before uploading, with the targetEverything() method targets added first, followed by the targetAll() method targets. See How do I Access File Deployments after an Upload for usage of the list.
© Gubutech(Xload) 2006