common-fileupload文件上传 表单值参数取值

用JSPSmartUpload或common-fileupload来做 
在表单里加了 
ENCTYPE= "multipart/form-data " 


直接用request.getParameter( "name ");   是取不到值的

 

因为JSPSmartUpload或common-fileupload又将参数值进行了一次封装,所以,直接取是没法取到的。

 

SmartUpload 取表单值值方法:

SmartUpload   mySmartUpload   =   new   SmartUpload(); 
mySmartUpload.initialize(config,   request,   response); 
mySmartUpload.upload(); 
name   =   mySmartUpload.getRequest().getParameter( "name "); 

common-fileupload取表单值方法:

if (FileUpload.isMultipartContent(requestContext)) {   
  
            DiskFileItemFactory factory = new DiskFileItemFactory();   
            factory.setRepository(new File(savaFilePath));   
            ServletFileUpload upload = new ServletFileUpload(factory);   
            // upload.setHeaderEncoding("gbk");50MB bytes 
            upload.setSizeMax(51200000);   
            List items = new ArrayList();   
            try {   
                items = upload.parseRequest(request);   
            } catch (FileUploadException e1) {   
                System.out.println("文件上传发生错误" + e1.getMessage());   
            }   
   
            Iterator it = items.iterator();   
            while (it.hasNext()) {   
                FileItem fileItem = (FileItem) it.next();   
                
                if (fileItem.isFormField()) {   
                	uploadResult="0";
//                	String   name   =   fileItem.getFieldName(); 
//                    if   (fileItem.getFieldName().equals("username")){ 
//                        System.out.println("fileItem.toString() "+fileItem.toString()+" "+fileItem.getString());
//                    } 
                	username=new String(fileItem.getString().getBytes(   
                    "iso8859-1"), "gbk");
					// System.out.println(fileItem.getFieldName()
					// + " 00 "
					// + fileItem.getName()
					// + " 01 "
					// + new String(fileItem.getString().getBytes(
					// "iso8859-1"), "gbk"));   
                }

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值