`

【转】upload.parseRequest(request)为空解决办法

 
阅读更多

android上传文件

httpclient 上传文件 后台struts使用action
 
action

HttpServletRequest request =ServletActionContext.getRequest();

DiskFileItemFactory factory =newDiskFileItemFactory();
factory.setSizeThreshold(4096);
System.out.println("保存路径:"+ getSavePath());
ServletFileUpload upload =newServletFileUpload(factory);
upload.setFileSizeMax(419430400);

List<?> items = upload.parseRequest(request);
Iterator<?> i = items.iterator();
while(i.hasNext()){
FileItemfi=(FileItem) i.next();
String filename =fi.getName();

if(filename !=null){
File file =newFile(filename);
File savefile =newFile(getSavePath(), file.getName());
fi.write(savefile);
System.out.println("保存路径:"+ getSavePath());
}
}

return SUCCESS;

 

 
htttpclient

FileBody bin =newFileBody(newFile("preview-ipad-01.jpg"));
HttpClient client =newDefaultHttpClient();
HttpPost post =newHttpPost("http://192.2.2.73:8080/upload/upload/uphc.do");
StringBody username =newStringBody("ssss");
StringBody password =newStringBody("dddd");

MultipartEntity reqEntity =newMultipartEntity();
reqEntity.addPart("username", username);
reqEntity.addPart("password", password);

reqEntity.addPart("data", bin);
post.setEntity(reqEntity);
System.out.println(post.getRequestLine()+"============");;

HttpResponse response = client.execute(post);
System.out.println("返回标志:"+ response.getStatusLine().getStatusCode());

HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());
if(resEntity !=null){
System.out.println("长度:"+ resEntity.getContentLength());
System.out.println("类型:"+ resEntity.getContentType());
System.out.println("编码:"+ resEntity.getContentEncoding());

InputStreamin= resEntity.getContent();
int i =in.available();
byte[] b =newbyte[i];
in.read(b);
in.close();

String xxx =newString(b);
System.out.println(xxx);


}

struts中要配置一下  

<beantype="org.apache.struts2.dispatcher.multipart.MultiPartRequest"
name="myRequestParser"class="com.mypkg.RequestParseWrapper"
scope="default"optional="true"/>
<constantname="struts.multipart.handler"value="myRequestParser"/>

这个必须有还要建立个空的类

publicclassRequestParseWrapperextendsJakartaMultiPartRequest{

publicvoid parse(HttpServletRequest servletRequest,String saveDir)throwsIOException
{

}
}

然后才能行
转自:http://school512.blog.163.com/blog/static/231691942013320113941216/
分享到:
评论

相关推荐

    common-fileupload实例:fileList = upload.parseRequest(request);上传file文件和form表单提交

    fileList = upload.parseRequest(request);上传file文件和form表单提交 common-fileupload实例

    Apache Commons fileUpload实现文件上传

    List&lt;FileItem&gt; items = upload.parseRequest(request); Iterator&lt;FileItem&gt; itr = items.iterator(); while (itr.hasNext()) { FileItem item = (FileItem) itr.next(); //检查当前项目是普通表单项目还是上传...

    利用org.apache.commons.fileupload上传多个文件

    http://blog.csdn.net/alanchen520/article/details/34409913

    jspsmartupload

    List fileItems = upload.parseRequest(request); //开始读取上传信息 Iterator iter = fileItems.iterator(); // 依次处理每个上传的文件 while(iter.hasNext()) { FileItem item = (FileItem) iter.next(); // ...

    JSP-文件图片上传-fileupload组件-commons-upload

    try {List items = upload.parseRequest(request);Iterator itr = items.iterator(); while (itr.hasNext()) {FileItem item = (FileItem) itr.next();if (item.isFormField()) { System.out.println("表单参数名:" ...

    ognl源码包值得用一用

    List&lt;FileItem&gt; list = upload.parseRequest(request); for (FileItem item : list) { if (item.isFormField()) { String name = item.getFieldName(); String value = item.getString("GBK")...

    上传文件+ajax进度条

    上传文件+ajax进度条 FileItemFactory factory = new DiskFileItemFactory(); // 通过该工厂对象创建...List items = upload.parseRequest(request); for (Iterator i = items.iterator(); i.hasNext();) {

    flex中的文件上传(简单例子)

    List fileItems = upload.parseRequest(request); Iterator iter = fileItems.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (!item.isFormField()) { ...

    java通过js上传文件

    items=upload.parseRequest (request).iterator(); while(items.hasNext()){ FileItem item=(FileItem) items.next(); if(!item.isFormField()){ String name=item.getName (); String fileName=name....

    fileupload

    items = upload.parseRequest(request); iterator = items.listIterator(); hd = tf.newTransformerHandler(); // Set the XML handler. Transformer serializer = hd.getTransformer(); // You'll serialize ...

    ajaxfileupload.js

    if (request.Files == null || request.Files.Count ) throw new ApplicationException("no file to be uploaded!"); var file = request.Files[0]; var filename = System.IO.Path.GetFileName(file.FileName);...

    java结合jsp写的上传文件代码

    fileList = sfu.parseRequest(request); } catch (FileUploadException e) {// 处理文件尺寸过大异常 if (e instanceof SizeLimitExceededException) { out.println("文件尺寸超过规定大小:" + MAX_SIZE + "字节...

    commons-fileupload-1.2.jar和commons-io-1.3.2.jar

    List fileItems = upload.parseRequest(req); // assume we know there are two files. The first file is a small // text file, the second is unknown and is written to a file on // the server Iterator ...

    Jsp文件上传下载(工具类源码)

    fileList = sfu.parseRequest(request); } catch (FileUploadException e) {// 处理文件尺寸过大异常 if (e instanceof SizeLimitExceededException) { out.println("文件尺寸超过规定大小:" + MAX_SIZE + "字节...

    Go处理文件上传

    func upload(w http.ResponseWriter,r *http.Request){ if r.Method==GET{ crutime:=time.Now().Unix() h:=md5.New() io.WriteString(h,strconv.FormatInt(curtime,10)) token:=fmt.Sprintf(%x,h.sum(nil))...

    nodejs提示:cross-device link not permitted, rename错误的解决方法

    node.js提示错误: Error: EXDEV: cross-device link not permitted, rename ‘C:\Users\THEDIS~1\AppData\Local\Temp\upload_9b46f1afc2f9ade074037c3fb707d271’ -&gt; ‘E:/node-rumen...form.parse(request, function

    Servlet上传文件

    * 目的是调用 parseRequest(request)方法 获得 FileItem 集合list , * * 5)在 FileItem 对象中 获取信息, 遍历, 判断 表单提交过来的信息 是否是 普通文本信息 另做处理 * 6) * 第一种. 用第三方 ...

    c# http post get

    HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream(), encoding); this.respHtml = reader.ReadToEnd(); foreach ...

    Node.js调用fs.renameSync报错(Error: EXDEV, cross-device link not permitted)

    function upload(response,request){ console.log("upload called"); var form = new formidable.IncomingForm(); console.log("about to parse"); form.parse(request, function(error, fields, files) { ...

    php.ini-development

    request_order ; Default Value: None ; Development Value: "GP" ; Production Value: "GP" ; session.gc_divisor ; Default Value: 100 ; Development Value: 1000 ; Production Value: 1000 ; session.hash_...

Global site tag (gtag.js) - Google Analytics