`
eastPoint
  • 浏览: 55142 次
  • 性别: Icon_minigender_1
  • 来自: 湖北武汉
社区版块
存档分类
最新评论

common-uploadfiles.1.2版本

    博客分类:
  • j2ee
阅读更多

servlet中测试成功:

java 代码
  1. String filesystempath = request.getSession().getServletContext().getRealPath("/");   
  2. ServletRequestContext srcontext = new ServletRequestContext(request);   
  3. System.out.println(srcontext.getCharacterEncoding());   
  4. System.out.println(srcontext.getContentType());   
  5. boolean isMultipart = ServletFileUpload.isMultipartContent(request);   
  6. if (isMultipart) {   
  7.     ServletFileUpload upload = new ServletFileUpload();   
  8.     try {   
  9. //Parse the request   
  10.     FileItemIterator iter = upload.getItemIterator(request);   
  11.     while (iter.hasNext()) {   
  12.         FileItemStream item = iter.next();   
  13.         //System.out.println(item.getContentType());
  14.         InputStream stream = item.openStream();   
  15.         if (item.isFormField()) {   
  16.                                            //这里处理form中的其它表单域内容   
  17.         } else {   
  18.                                            //这里处理上传对象   
  19.         String clientrealpath = item.getName();   
  20.         clientrealpath = clientrealpath.replace("\\", "\\\\");   
  21. //System.out.println(clientrealpath);   
  22. String filename = StringHelper.getFileName(clientrealpath);   
  23. //System.out.println(filesystempath+filename);   
  24. File newfile = new File(filesystempath+filename);   
  25. OutputStream os =new FileOutputStream(newfile);   
  26. byte[] b = new byte[8192];   
  27. int len;   
  28. while ((len = stream.read(b)) != -1) {   
  29. os.write(b, 0, len);   
  30. os.flush();   
  31. os.close();   
  32. stream.close();   
  33. // Process the input stream   
  34. }   
  35. }   
  36. catch (FileUploadException e) {   
  37. e.printStackTrace();   
  38. }   
  39. }  
分享到:
评论
1 楼 xuey210 2009-10-31  
struts 的action 中一定不能成功

相关推荐

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

    -下载后解压zip包,将commons-fileupload-1.1.1.jar,和commons-io-1.2.jar(这里我们用的是更新的版本,但是用法是一样的)复制到tomcat的webapps\你的webapp\WEB-INF\lib\下,如果目录不存在请自建目录。 新建一个...

    commons-fileupload-1.2.2.jar必须依赖包.rar

    此时,打开选择框,我们选择默认的【copy files】,点击【OK】关闭。然后我们就可以在lib文件夹下看到我们复制成功的jar包。  4、此时,只是把jar包复制到项目中,还不能使用。我们再在项目名上右击,依次选择...

    ZendFramework中文文档

    9.4.3. Basic Zend_Date Operations Common to Many Date Parts 9.4.3.1. List of Date Parts 9.4.3.2. List of Date Operations 9.4.4. Comparing Dates 9.4.5. Getting Dates and Date Parts 9.4.6. Working ...

    PHPBB论坛拍卖插件phpbb-auction

    # Remember to upload all the language files and template files to all your # language packs and template directories # # If you use FTP please remember to use ASCII mode for text files (*.php, *.tpl) ...

    Java邮件开发Fundamentals of the JavaMail API

    To use the JavaMail 1.2 API, download the JavaMail 1.2 implementation, unbundle the javamail-1_2.zip file, and add the mail.jar file to your CLASSPATH. The 1.2 implementation comes with an SMTP, ...

    PHP基础教程 是一个比较有价值的PHP新手教程!

    $a = 1.2e3; # 双精度数的指数形式 字符串 字符串可以由单引号或双引号引出的字段定义。注意不同的是被单引号引出的字符串是以字面定义的,而双引号引出的字符串可以被扩展。反斜杠(\)可以被用来分割某些...

Global site tag (gtag.js) - Google Analytics