zl程序教程

您现在的位置是:首页 >  后端

当前栏目

SpringMVC的上传和下载详解编程语言

2023-06-13 09:20:46 时间
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; @Controller public class MyController { @RequestMapping("download.do") public ResponseEntity byte[] download() throws IOException { File file=new File("F://Y2//OA//.metadata//.me_tcat//webapps//SpringMVC_fileupload//images//111.jpg"); HttpHeaders headers = new HttpHeaders(); String fileName=new String("你好.jpg".getBytes("utf-8"),"iso-8859-1");//为了解决中文名称乱码问题 headers.setContentDispositionFormData("attachment", fileName); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); return new ResponseEntity byte[] (FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED); }
 form action="${pageContext.request.contextPath}/frist.do" method="post" enctype="multipart/form-data" 

 文件: input type="file" name="uploadFile"/ br/ 

 input type="submit" value="上传"/ 

 /form 

 a href="${pageContext.request.contextPath}/download.do?111.jpg" 下载 /a 

注解版配置欢迎你的使用~~~

 

16079.html

cjava