解決response.getOutputStream()輸出頁面中文亂碼
阿新 • • 發佈:2021-01-16
技術標籤:工具類解決response中文亂碼
import org.apache.commons.io.IOUtils; import java.nio.charset.StandardCharsets; @RequestMapping(value = "aaa", method = {RequestMethod.POST, RequestMethod.GET}) public void downloadResult(HttpServletResponse response) { InputStream inputStream = null; response.setContentType("text/html;charset=UTF-8"); inputStream = new ByteArrayInputStream("sssswid錯誤!!!".getBytes(StandardCharsets.UTF_8)); response.setCharacterEncoding(StandardCharsets.UTF_8.name()); IOUtils.copy(inputStream, response.getOutputStream()); response.getOutputStream().flush(); response.getOutputStream().close(); }