commons-fileupload maven

commons-fileupload maven

版本:v1.2.2 官方版大小:53KB

类别: 编程工具 系统:WinAll, WinXP, Win7, Win8

立即下载
  • commons-fileupload maven v1.2.2 官方版0
  • commons-fileupload maven v1.2.2 官方版1

commons-fileupload.jar是maven中的实现文件上传的控制大小的组件,通过这款开源工具,让用户在调用java语言时可以更加便捷,绿色资源网诚意推荐!

commons-fileupload-1.2.2.jar介绍

使用最为广泛的Java文件上传组件,Struts本身采用这个包来处理文件上传。文档非常详细、简单易用。

commons-fileupload-1.2.2.jar

使用Commons-fileupload组件实现文件下载

// 文件的下载

    public void doGet(HttpServletRequest request, HttpServletResponse response)

           throws ServletException, IOException {

       // 找到用户所选定的文件

       String uuidname = request.getParameter(“filename”);

       uuidname = new String(uuidname.getBytes(“ISO8859-1”), “utf-8”);

       String realname = uuidname.substring(uuidname.indexOf(“_”)+1);

       // 确定文件的保存位置

       String savePath = getFileAddr(realname);

       File f = new File(savePath + “\\” + uuidname);

       //System.out.println(savePath+“<br/>”+uuidname);

       if (f.exists()) {

           // 设置应答的相应消息头

           response.setcontentType(“application/x-msdownload”);

           String str = “attachment;filename=”+ java.NET.URLEncoder.encode(realname, “utf-8”);

           response.setHeader(“Content-Disposition”, str);

           // 创建一 个输入流对象和指定的文件相关联

           FileInputStream in = new FileInputStream(f);

           // 从response对象中获取到输出流对象

           OutputStream out = response.getOutputStream();

           // 从输入流对象中读数据写入到输出流对象中

           byte[] buff = new byte[1024];

           int len = 0;

           while ((len = in.read(buff)) > 0) {

              out.write(buff, 0, len);

           }

       }else{

           request.setAttribute(“message”, “下载资源不存在”);

           request.getRequestDispatcher(“/message.jsp”)。forward(request, response);

       }

    }

    //根据文件名查找路径

    private String getFileAddr(String filename) {

       int dir1 = filename.hashCode() & 0x0f;

       int dir2 = filename.hashCode()》4 & 0x0f;

       System.out.println(dir1+“====”+dir2);

       String savePath = this.getServletContext()。getRealPath(“WEB-INF/upload”)

              + “\\” + dir1 + “\\” + dir2;

       System.out.println(“=============”+savePath);

       return savePath;

    }

查看全部

更新时间:2017-07-24
网友评论
我要跟贴
取消
猜你喜欢
  • maven仓库

maven仓库更多>>

maven仓库是软件工程师开发中常用的远程仓库,maven远程仓库地址非常多,但是需要maven配置远程仓库和maven添加远程仓库这的感觉还是非常的不错的,maven配置也是相当的不错的,需要这个软件千万不要错过机会了,快来绿色资源网下载吧!

同类推荐
热门精品
最新应用