Building an Application With FileUpload


Now that we understand the basic design of the FileUpload component, let's look at a simple application that makes use of FileUpload. As shown in Figure 2-6, the JSP pages provide a user interface, and a set of Java helper classes are used to configure and invoke the FileUpload component.

Figure 2-6. FileUpload application overview.


By centralizing the access to the FileUpload component in the helper classes, the configuration of the FileUpload component can be changed without updating the JSP pages. For example, you may want to configure the maximum permissible file size, the kind of files that may be updated, or the buffering of uploaded data to memory or disk.

FileUpload Application User Interface

A user visiting the file upload web application is first prompted to add a file, as shown in Figure 2-7.

Figure 2-7. Add File request.


Clicking the link takes the user to a file upload form, as shown in Figure 2-8. Clicking the Browse . . . button (a standard browser user interface widget) prompts the user to select a file on disk. Here, we've selected a file on the C:\ drive. Clicking Upload sends the selected file to the server.

Figure 2-8. File Upload form.


The file is uploaded, and then the user is returned to the file list, as shown in Figure 2-9. You'll notice that the user can click on the file name to download the file again via HTTP, the file size is reported in bytes, and the MIME type (as reported by the browser) is listed. Additionally, the Location link points to the file location on the server's file system. Finally, clicking Delete will remove the file from disk.

Figure 2-9. Uploaded File list.


The user interface is quite straightforward, and in the next section we'll look at the code required to build it.



    Apache Jakarta Commons(c) Reusable Java Components
    Real World Web Services
    ISBN: N/A
    EAN: 2147483647
    Year: 2006
    Pages: 137
    Authors: Will Iverson

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net