当文件上传 无法获取request值时 的操作

来源:互联网 发布:新浪微博修改个性域名 编辑:程序博客网 时间:2024/06/03 03:28
还有一种方法就是使用jspsmartupload 
jar包为:jsmartcom_zh_CN  

表单中enctype="multipart/form-data"的意思,是设置表单的MIME编码。默认情况,这个编码格式是application/x-www-form-urlencoded,不能用于文件上传;只有使用了 multipart/form-data,才能完整的传递文件数据

但是设置了 enctype="multipart/form-data" ,除了file类型表单能获取到,其他value通过request.getParameter都得不到。这种情况下我们可以利用组件来解决该问题,例如用 jspsmartupload组件

   com.jspsmart.upload.SmartUpload su = new   com.jspsmart.upload.SmartUpload();
   su.initialize(pageContext);
   su.service(request, response);
   su.setTotalMaxFileSize(100000000);
   su.setAllowedFilesList("zip,rar");
   su.setDeniedFilesList("exe,bat,jsp,htm,html,,");
   su.upload();

   String Name = su.getRequest().getParameter("Name");
   String TYPE_ID = su.getRequest().getParameter("Type");

通过 su.getRequest().getParameter("value");就可以了,su.upload()好象必须放在前面,测试中将su.upload()放在获取参数后面不成功。

原创粉丝点击