• 大小: 3.47MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-11-20
  • 语言: Java
  • 标签: java  ssh  

资源简介

简易的上传代码方便新手理解,Struts2+Spring+hibernate上传

资源截图

代码片段和文件信息

package Uploadaction;

import java.text.NumberFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.fileupload.ProgressListener;


public class MyProgressListener implements ProgressListener {
 private HttpSession session;
    public MyProgressListener(HttpServletRequest request){
        session = request.getSession();
    }
    @Override
    public void update(long pBytesRead long pContentLength int pItems) {
        //将数据进行格式化
        //已读取数据由字节转换为M
        double readM=pBytesRead/1024.0/1024.0;
        //已读取数据由字节转换为M
        double totalM=pContentLength/1024.0/1024.0;
        //已读取百分百
        double percent=readM/totalM;
        
        //格式化数据
        //已读取
        String readf=dataFormat(pBytesRead);
        //总大小
        String totalf=dataFormat(pContentLength);
        //进度百分百
        NumberFormat format=NumberFormat.getPercentInstance();
        String progress=format.format(percent);
        
        //将信息存入session
        session.setAttribute(“progress“ progress);
        
        //打印消息到控制台
        System.out.println(“pBytesRead===>“+pBytesRead);
        System.out.println(“pContentLength==>“+pContentLength);
        System.out.println(“pItems===>“+pItems);
        System.out.println(“readf--->“+readf);
        System.out.println(“totalf--->“+totalf);
        System.out.println(“progress--->“+progress);
    }
    /**
     * 格式化读取数据的显示
     * @param data要格式化的数据 单位byte
     * @return 格式化后的数据,如果小于1M显示单位为KB,如果大于1M显示单位为M
     */
    public String dataFormat(double data){
        String formdata=““;
        if (data>=1024*1024) {//大于等于1M
            formdata=Double.toString(data/1024/1024)+“M“;
        }else if(data>=1024){//大于等于1KB
            formdata=Double.toString(data/1024)+“KB“;
        }else{//小于1KB
            formdata=Double.toString(data)+“byte“;
        }
        return formdata.substring(0 formdata.indexOf(“.“)+2);
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        893  2019-01-14 11:42  uploadfile\.classpath

     文件       1043  2019-01-17 15:14  uploadfile\.project

     文件        503  2019-01-14 11:41  uploadfile\.settings\.jsdtscope

     文件        364  2019-01-14 11:41  uploadfile\.settings\org.eclipse.jdt.core.prefs

     文件        482  2019-01-17 15:14  uploadfile\.settings\org.eclipse.wst.common.component

     文件        305  2019-01-14 11:41  uploadfile\.settings\org.eclipse.wst.common.project.facet.core.xml

     文件         49  2019-01-14 11:41  uploadfile\.settings\org.eclipse.wst.jsdt.ui.superType.container

     文件          6  2019-01-14 11:41  uploadfile\.settings\org.eclipse.wst.jsdt.ui.superType.name

     文件       2512  2019-01-18 14:52  uploadfile\build\classes\Uploadaction\MyProgressListener.class

     文件       4152  2019-01-18 14:52  uploadfile\build\classes\Uploadaction\UploadServlet.class

     文件       2300  2019-01-11 11:48  uploadfile\src\Uploadaction\MyProgressListener.java

     文件       3262  2019-01-17 15:13  uploadfile\src\Uploadaction\UploadServlet.java

     文件    3472959  2019-01-12 11:36  uploadfile\WebContent\adfadf.jpg

     文件        598  2014-05-12 13:40  uploadfile\WebContent\filejd.jsp

     文件       3112  2019-01-16 11:43  uploadfile\WebContent\Fileupload.jsp

     文件       1591  2019-01-16 14:43  uploadfile\WebContent\index.jsp

     文件      93100  2019-01-12 11:53  uploadfile\WebContent\jquery-1.10.2.min.js

     文件         39  2019-01-14 11:41  uploadfile\WebContent\meta-INF\MANIFEST.MF

     文件        839  2014-05-13 11:15  uploadfile\WebContent\uploadError.jsp

     文件      57779  2011-10-04 23:08  uploadfile\WebContent\WEB-INF\lib\commons-fileupload-1.2.1.jar

     文件      87776  2011-10-04 23:08  uploadfile\WebContent\WEB-INF\lib\commons-io-1.3.2.jar

     文件       1012  2019-01-17 15:14  uploadfile\WebContent\WEB-INF\web.xml

     目录          0  2019-01-18 14:52  uploadfile\build\classes\Uploadaction

     目录          0  2019-01-17 15:15  uploadfile\WebContent\WEB-INF\lib

     目录          0  2019-01-18 14:52  uploadfile\build\classes

     目录          0  2019-01-17 15:15  uploadfile\src\Uploadaction

     目录          0  2019-01-17 15:15  uploadfile\WebContent\meta-INF

     目录          0  2019-01-14 15:14  uploadfile\WebContent\upload

     目录          0  2019-01-17 15:15  uploadfile\WebContent\WEB-INF

     目录          0  2019-01-17 15:15  uploadfile\.settings

............此处省略7个文件信息

评论

共有 条评论