public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gb2312");////在PrintWriter前面有效果
PrintWriter out = response.getWriter();
request.setCharacterEncoding("utf-8");
// response.setContentType("text/html;charset=gb2312");////在PrintWriter后面无效果
userId1 = request.getParameter("userId1");// ///需要2个参数
userId2 = request.getParameter("userId2");
一定要注意语句的顺序!!!!
本文介绍如何在Servlet中正确设置字符编码以避免乱码问题,包括设置响应内容类型及请求字符集编码的具体实现。
2151

被折叠的 条评论
为什么被折叠?



