response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setCharacterEncoding("GBK");
response.setContentType("text/html,charset=GBK");这些要写在
PrintWriter out = response.getWriter();之前
本文介绍如何在Java Servlet中设置HTTP响应头以避免缓存,并正确设置字符编码为GBK,确保中文内容能正常显示。
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setCharacterEncoding("GBK");
response.setContentType("text/html,charset=GBK");PrintWriter out = response.getWriter();
被折叠的 条评论
为什么被折叠?