小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

解決當(dāng)FORM的ENCTYPE="multipart/form-data" 時reques...

 WindySky 2008-12-18

今天在原來上傳文件頁面的基礎(chǔ)上,想添加一段文件的簡介

因為同時要上傳文件,所以ENCTYPE="multipart/form-data" 必須要加在form里面

可是這樣的話,我再Servlet里面用request.getParameter()方法無論如何都只是獲得null值,

不是一般的郁悶,百度了一下,有人出現(xiàn)了同樣的問題可是它用的是JSPsmartupload組件實現(xiàn)文件上傳的,

而我用的commons fileupload組件,仔細(xì)看了一下這個組件的api,可是英語太差了,沒有發(fā)現(xiàn)相關(guān)的信息

我又嘗試用session傳遞參數(shù),可是發(fā)現(xiàn)有點麻煩,因為在表單提交之時你就得賦給session表單上它的數(shù)值,

這似乎要JavaScript,可是偶也不會,

后來只有g(shù)oogle了,搜索了一些中文網(wǎng)頁,也沒有找到資料,試試不限制語言,呵呵呵,一大片,后來被俺發(fā)

現(xiàn)了這個

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./cos/index.html
2. invoke getParameters() on com.oreilly.servlet.MultipartRequest
Solution B:
1. download http://jakarta./commons/sandbox/fileupload/
2. invoke readHeaders() in
org.apache.commons.fileupload.MultipartStream
Solution C:
1. download http://users./wbrameld/multipartformdata/
2. invoke getParameter on
com.bigfoot.bugar.servlet.http.MultipartFormData
Solution D:
Use Struts. Struts 1.1 handles this automatically.
說是不詳細(xì),接著往下看,另一種解決方法
> Solution B:
> 1. download
> http://jakarta./commons/sandbox/fileupload/
> 2. invoke readHeaders() in
> org.apache.commons.fileupload.MultipartStream

The 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./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.

按照上面的步驟來,果然一切都o(jì)k,GOOGLE真不錯,主要是getFieldName和getString,
雖然說這種做法有一點麻煩,但稍微判斷加工一下,總比獲取不到強(qiáng)

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多