I cannot read the submitter using request.getParameter("submitter") (it returns null). ]
Situation:
javax.servlet.HttpServletRequest.getParameter(String) returns null when the ContentType is multipart/form-data
Solutions:
Solution A:
1. download http://www.servlets.com/cos/index.html
2. invoke getParameters() on com.oreilly.servlet.MultipartRequest
Solution B:
1. download http://jakarta.apache.org/commons/sandbox/fileupload/
2. invoke readHeaders() in
org.apache.commons.fileupload.MultipartStream
Solution C:
1. download http://users.boone.net/wbrameld/multipartformdata/
2. invoke getParameter on
com.bigfoot.bugar.servlet.http.MultipartFormData
Solution D:
Use Struts. Struts 1.1 handles this automatically.
说是不详细,接着往下看,另一种解决方法
> Solution B:> 1. download > http://jakarta.apache.org/commons/sandbox/fileupload/> 2. invoke readHeaders() in > org.apache.commons.fileupload.MultipartStreamThe Solution B as given by my dear friend is a bit hectic and a bit complex
We can try the following solution which I found much simpler (at least in usage).1. Download one of the versions of UploadFile from http://jakarta.apache.org/commons/fileupload/2. Invoke parseRequest(request) on org.apache.commons.fileupload.FileUploadBase which returns list of org.apache.commons.fileupload.FileItem objects. 3. Invoke isFormField() on each of the FileItem objects. This determines whether the file item is a form paramater or stream of uploaded file. 4. Invoke getFieldName() to get parameter name and getString() to get parameter value on FileItem if it's a form parameter. Invoke write(java.io.File) on FileItem to save the uploaded file stream to a file if the FileItem is not a form parameter.
按照上面的步骤来,果然一切都ok,GOOGLE真不错,主要是getFieldName和getString