mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add ServletUtil 测试违反法 和 注释;方便调用这进行调用;
目前暂时发现:safafi浏览器出现乱码
This commit is contained in:
parent
65a43f5318
commit
0d0f70bf15
@ -549,6 +549,17 @@ public class ServletUtil {
|
|||||||
* @param response 响应对象{@link HttpServletResponse}
|
* @param response 响应对象{@link HttpServletResponse}
|
||||||
* @param in 需要返回客户端的内容
|
* @param in 需要返回客户端的内容
|
||||||
* @param contentType 返回的类型
|
* @param contentType 返回的类型
|
||||||
|
* 如:
|
||||||
|
* 1、application/pdf、
|
||||||
|
* 2、application/vnd.ms-excel、
|
||||||
|
* 3、application/msword、
|
||||||
|
* 4、application/vnd.ms-powerpoint
|
||||||
|
* docx、xlsx 这种 office 2007 格式 设置 MIME;网页里面docx 文件是没问题,但是下载下来了之后就变成doc格式了
|
||||||
|
* https://blog.csdn.net/cyh2260629/article/details/73824760
|
||||||
|
* 5、MIME_EXCELX_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
||||||
|
* 6、MIME_PPTX_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
||||||
|
* 7、MIME_WORDX_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
||||||
|
* 8、MIME_STREAM_TYPE = "application/octet-stream;charset=utf-8"; #原始字节流
|
||||||
* @param fileName 文件名
|
* @param fileName 文件名
|
||||||
* @since 4.1.15
|
* @since 4.1.15
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package cn.hutool.extra.servlet;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ServletUtil工具类测试
|
||||||
|
* @author dazer
|
||||||
|
* @date 2021/3/24 15:02
|
||||||
|
* @see ServletUtil
|
||||||
|
*/
|
||||||
|
public class ServletUtilTest {
|
||||||
|
@Test
|
||||||
|
public void writeTest() {
|
||||||
|
HttpServletResponse response = null;
|
||||||
|
byte[] bytes = new String("地球是我们共同的家园,需要大家珍惜.").getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
//下载文件
|
||||||
|
// 这里没法直接测试,直接写到这里,方便调用;
|
||||||
|
if (response != null) {
|
||||||
|
String fileName = "签名文件.pdf";
|
||||||
|
String contentType = "application/pdf";// application/octet-stream、
|
||||||
|
response.setCharacterEncoding(StandardCharsets.UTF_8.name()); // 必须设置否则乱码; 但是 safari乱码
|
||||||
|
ServletUtil.write(response, new ByteArrayInputStream(bytes), contentType, fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user