package com.artpower.controller;
import java.io.File;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.FileUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class ArtPowerController {
@RequestMapping("gifts.action")
public ModelAndView gifts(HttpServletRequest request, HttpServletResponse response) {
request.getRequestURL();
System.out.println("--request.getRequestUrl--");
System.out.println(request.getRequestURL());
File file = new File("D:\\gifts");
//获取文件名
String[] arr = file.list();
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
ModelAndView mav = new ModelAndView();
mav.addObject("arr", arr);
mav.setViewName("gifts");
return mav;
}
@RequestMapping("download.action")
public ResponseEntity<byte[]> download(String down) throws IOException {
byte[] by = down.getBytes("ISO-8859-1");
down = new String(by,"utf-8");
String path = "D:\\gifts/" + down;
System.out.println("**path**");
System.out.println(path);
File file = new File(path);
HttpHeaders headers = new HttpHeaders();
String fileName = new String(down.getBytes("utf-8"), "iso-8859-1");
headers.setContentDispositionFormData("attachement", fileName);
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
java查询本地文件夹动态显示并下载文件
共30个文件
jar:24个
xml:2个
jsp:2个
1星 需积分: 31 17 下载量 173 浏览量
2017-09-05
10:48:14
上传
评论
收藏 5.96MB RAR 举报
温馨提示
根据路径动态查找显示文件并点击下载,如果显示的是文件夹自行处理,语句是 if(file.isDirectory){},改成自己的就能用
资源推荐
资源详情
资源评论
收起资源包目录
springMVC_查询下载.rar (30个子文件)
springMVC_查询下载
WebContent
WEB-INF
jsp
gifts.jsp 618B
lib
log4j.jar 359KB
spring-orm-3.2.9.RELEASE.jar 376KB
spring-core-3.2.9.RELEASE.jar 864KB
spring-aspects-3.2.9.RELEASE.jar 50KB
jstl-1.2.jar 405KB
spring-context-3.2.9.RELEASE.jar 846KB
spring-oxm-3.2.9.RELEASE.jar 74KB
spring-test-3.2.9.RELEASE.jar 447KB
spring-aop-3.2.9.RELEASE.jar 330KB
spring-build-src-3.2.9.RELEASE.jar 71KB
spring-jms-3.2.9.RELEASE.jar 201KB
spring-instrument-3.2.9.RELEASE.jar 7KB
spring-tx-3.2.9.RELEASE.jar 237KB
spring-expression-3.2.9.RELEASE.jar 192KB
spring-web-3.2.9.RELEASE.jar 618KB
spring-beans-3.2.9.RELEASE.jar 599KB
spring-struts-3.2.9.RELEASE.jar 35KB
commons-logging.jar 26KB
spring-framework-bom-3.2.9.RELEASE.jar 6KB
commons-io-1.3.2.jar 86KB
spring-webmvc-3.2.9.RELEASE.jar 623KB
commons-fileupload-1.2.1.jar 56KB
spring-jdbc-3.2.9.RELEASE.jar 396KB
com.springsource.org.apache.commons.logging-1.1.1.jar 60KB
web.xml 1KB
index.jsp 411B
META-INF
MANIFEST.MF 39B
src
com
artpower
controller
ArtPowerController.java 2KB
Valentine-servlet.xml 989B
共 30 条
- 1
资源评论
- wx_tangjinjinwx2018-08-13骗子,骗我3积分
我是小酒
- 粉丝: 2669
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功