免费字体大全

当前位置:首页>软件下载

时间:2017-07-24   访问量:5


commons-fileupload maven 属性

软件大小:53KB 软件语言:中文 软件类型:国产软件 软件类别:免费软件 / 编程工具 更新时间:2017-07-24 15:39 运行环境:WinAll, WinXP, Win7, Win8 软件等级: 软件厂商: 官方网站:暂无

commons-fileupload maven 软件介绍

软件标签: 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;

}

下载地址

⚠温馨提示⚠:资源来自于网络,仅供交流学习及信息展示之用,下载后请在24小时之内删除!如有侵犯您的权益,请联系我们删除。