利用 spring mvc ResponseEntity 做文件下载
来源:互联网 发布:没经验能做淘宝客服吗 编辑:程序博客网 时间:2024/05/17 08:02
controller:
@RequestMapping(value = "/cmpSts/{cmpId}", method = RequestMethod.GET) public ResponseEntity<byte[]> cmpSts(@PathVariable int cmpId, HttpServletRequest request, HttpServletResponse response) throws Exception { Locale local=request.getLocale(); String[] file = new String[]{"a.txt","a,b"}; byte[] bs = file[1].getBytes("UTF-8"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); headers.setContentDispositionFormData("attachment", new String(file[0].getBytes("UTF-8"), "ISO8859-1")); //解决文件名中文乱码问题 return new ResponseEntity<byte[]>(bs, headers, HttpStatus.CREATED); }
XML:
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> <property name="messageConverters"> <list> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="writeAcceptCharset" value="false" /> <property name="supportedMediaTypes"> <list> <value>text/plain;charset=UTF-8</value> </list> </property> </bean> <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/> <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> </list> </property> </bean> </list> </property> </bean>
0 0
- 利用 spring mvc ResponseEntity 做文件下载
- 利用 spring mvc ResponseEntity 做文件下载
- ResponseEntity实现文件下载
- spring mvc @ResponseStatus 和 ResponseEntity
- java鬼混笔记:用Spring的ResponseEntity进行文件下载
- springmvc ResponseEntity 下载文件损坏问题解决方法
- SpringMVC使用ResponseEntity实现文件下载
- springmvc ResponseEntity 下载文件损坏问题解决方法
- 使用springmvc中ResponseEntity下载文件
- Spring MVC 文件下载
- Spring mvc 文件下载
- spring mvc 文件下载
- Spring MVC下载文件
- spring mvc 文件下载
- Spring mvc 文件下载
- Spring MVC文件下载
- spring mvc下载文件
- Spring MVC 文件下载
- 最近用bootstrap的时候发现了一些问题
- 2种判断(获取)栈顶activity的方法
- Redis配置文件详解
- iOS Developer:真机测试证书申请
- HTTP 状态码
- 利用 spring mvc ResponseEntity 做文件下载
- OneNote2016安装代码高亮插件-NoteHightlight
- Caffe windows下入门级别的从编译到训练然后到分类(用python接口)Caffe编译和环境(二)
- MD5加密
- TCP/IP数据包格式详解-包括数据链路层的头部
- jsp+servlet实现最基本的注册登陆功能
- 图像处理学习笔记之图像的几何变换(1)坐标映射
- CodeForces
- Windchill 事务的开启与关闭