mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add ServletUtil 测试违反法 和 注释;方便调用这进行调用;
目前暂时发现:safafi浏览器出现乱码
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user