Do you just not use ActionForm, David?

Michael McGrady

Pawson, David wrote:

If these questions are asked on the main list,
others can learn too?



-----Original Message-----
From: Caroline Jen I am trying to upload files from clients machine.



I understand that we must specify METHOD=post and ENCTYPE="multipart/form-data" in the <FORM> tag.
Would you please help me with a number of questions:
1. Once the client makes a selection from his/her PC, the file name will appear in the text field. How do I 'save the file name'? within the servlet,


        DiskFileUpload upload = new DiskFileUpload();
        boolean isMultipart = FileUpload.isMultipartContent(request);
        if (!isMultipart) {
            logger.warn(userName(request)+"File upload is not multipart");
            ULerr = FORMNOTMULTIPART;
        }
        // Set upload parameters
   ...
        try {
            java.util.List items = upload.parseRequest(request);
            // Process the uploaded items
            String [] parms = gParms (items, request);
            String [] gfileList = gFiles (items, request);

I have some plain textboxes as well as the list of files.
I'm re-working this piece;
currently

  /**
    *unwrap filelist, return as string array.
    **/
   public String [] gFiles(java.util.List items,HttpServletRequest request){
        String[] retval=null;
        java.util.Iterator iter = items.iterator();
        int pos=0;
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            if (!item.isFormField()) {
                String fieldName = item.getFieldName();
                String fileName = item.getName();
                String contentType = item.getContentType();
                boolean isInMemory = item.isInMemory();
                long sizeInBytes = item.getSize();
                if (sizeInBytes == 0){
                    logger.info(userName(request)+" No files selected");
                    out.println("<li>No files selected</li>");
                }else{ // file OK
                pos +=1;
                retval[pos] = fileName; // full path and filename
                }
            }//end of if is Form field
        }// end of while more items

        return retval;

   }// end of gfiles()

That collects the list of filenames, prior to uploading them?
 That should be sufficient to get you started.
The rest of my code is messed with the functionality I need?

HTH DaveP.








2. Do I save what I download from the
http://www.htmlhelp.com/reference/html40/forms/input.html
in my $TOMCAT/common/lib directory? Do I have to save it in my $TOMCAT/webapps/AppName/WEB-INF/lib
directory.


No, its just java once you have the filenames. Just write them whereever you need them 
to be.


3. Are there anything else I have to do to make file uploading work?


Patience :-) HTH DaveP.
Shout again if I can help.







--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to