找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 16|回复: 0

commons-fileupload maven

[复制链接]

32万

主题

0

回帖

96万

积分

超级版主

积分
964681
发表于 2025-3-14 11:06:04 | 显示全部楼层 |阅读模式
软件标签:  jar包   .jar
commons-fileupload.jar是maven中的实现文件上传的控制大小的组件,通过这款开源工具,让用户在调用java语言时可以更加便捷,绿色资源网诚意推荐!
commons-fileupload-1.2.2.jar介绍
使用最为广泛的java文件上传组件,struts本身采用这个包来处理文件上传。文档非常详细、简单易用。



使用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;

}
<a class="a_0" href="http://122.51.165.215/img/09编程开发/编程工具/57411/57411_101.png" >



aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|ziyuan80.com

GMT+8, 2025-8-17 10:46 , Processed in 0.085233 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表