commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Forte, Graham" <graham.fo...@ngc.com>
Subject commons newbie
Date Tue, 30 Mar 2004 14:11:04 GMT
Hello,
I am trying to use the commons 1.0 that I downloaded yesterday. 
I have a few questions that I could not find the answer to on the commons home page.
First of all, I had downloaded the fileUpload 1.5 from javazoom, I decided to go with commons
instead. I believe that they use the commons jar file and it is named fileupload.jar(true?).I
was able to get the samle code to work using the fileupload.jar.

Where can I find the archives of this users list?

How do I import the commons jar file?
I had put the jar file in my \webapps\SAMNEW\WEB-INF\lib directory and did the following 
<%@page import= "java.util.*,org.apache.commons.commons-fileupload-1.0.jar%>
when I compile I get the following error:
common$jsp.java [4:1] ';' expected
import org.apache.commons.commons-fileupload-1.0.jar;//pointing to the hyphen following commons.
Do I need to rename the jar file.

How can I specify the directory that the file is uploaded to?

If there is a newbie tutorial link somewhere that would be great.

Thanks in advance!
Graham


here is the code example I was able to find:
This works using the above described jar but not the new jar that I just got. Also It uploads
it into my webapps/myapp directory (which I need to change)
*********************************************************************************************************************
//a. Check if the input request has been sent as multipart form data.

// first check if the upload request coming in is a multipart request
boolean isMultipart = FileUpload.isMultipartContent(request);
//b. Create a handler for this request, and use it to parse the request. Upon parsing, all
of the form items are available in a list.

DiskFileUpload upload = new DiskFileUpload();
    
// parse this request by the handler
// this gives us a list of items from the request
List items = upload.parseRequest(request);
//c. Iterate over this list to access individual file items. To distinguish between items
that are actual uploaded files versus regular form fields, use the isFormField() method. Based
on the required processing scenarios, we could save the uploaded files, access them byte by
byte, or open an input stream on them.

Iterator itr = items.iterator();

while(itr.hasNext()) {
	FileItem item = (FileItem) itr.next();
        
	// check if the current item is a form field or an uploaded file
	if(item.isFormField()) {
            
	// get the name of the field
	String fieldName = item.getFieldName();
	
	// if it is name, we can set it in request to thank the user
	if(fieldName.equals("name"))
		request.setAttribute("msg", "Thank You: " + item.getString());
		
	} else {

		// the item must be an uploaded file save it to disk. Note that there
		// seems to be a bug in item.getName() as it returns the full path on
		// the client's machine for the uploaded file name, instead of the file
		// name only. To overcome that, I have used a workaround using
		// fullFile.getName().
		File fullFile  = new File(item.getName());  
		File savedFile = new File(getServletContext().getRealPath("/"),fullFile.getName());
		item.write(savedFile);
	}
}
*************************************************************************************************************************************

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message