On The Way

解决当FORM的ENCTYPE="multipart/form-data" 时request.getParameter()获取不到值的方法

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/fileupload/ 
    2. invoke readHeaders() in org.apache.commons.fileupload.MultipartStream
    Or
    1. Invoke parseRequest(request) on org.apache.commons.fileupload.FileUploadBase which returns list of org.apache.commons.fileupload.FileItem objects.
   2. Invoke isFormField() on each of the FileItem objects. This determines whether the file item is a form paramater or stream of uploaded file.
   3. 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.

  • 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.

posted on 2008-03-26 10:38 梁健 阅读(2720) 评论(2)  编辑  收藏 所属分类: jsp/servlet

Feedback

# re: 解决当FORM的ENCTYPE="multipart/form-data" 时request.getParameter()获取不到值的方法 2009-03-03 10:52 fd

没人看的懂你说的。。。要么就别写  回复  更多评论   

# re: 解决当FORM的ENCTYPE="multipart/form-data" 时request.getParameter()获取不到值的方法 2012-05-18 17:30 路人甲

smartupload.getRequest().getParameter("cwname")这样就可以了  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航: