标签:
直接上代码
public class FileManagerService extends HttpServlet { public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // request.setCharacterEncoding("utf-8"); // 一失足成千古恨,再回首已百年身 String liaolongjun = request.getParameter("liaolongjun"); System.out.println(liaolongjun); request.setCharacterEncoding("utf-8"); liaolongjun = request.getParameter("liaolongjun"); System.out.println(liaolongjun); request.getRequestDispatcher("index.jsp").forward(request, response); } }
1、把 request.setCharacterEncoding("utf-8"); 放在最上面,输出正常中文
2、把 request.setCharacterEncoding("utf-8"); 放在中间,前后输出来的中文都是乱码
.-‘ _..`.
/ .‘_.‘.‘
| .‘ (.)`.
;‘ ,_ `.
.--.__________.‘ ; `.;-‘
| ./ /
| | /
`..‘`-._ _____, ..‘
/ | | | |\ \
/ /| | | | \ \
/ / | | | | \ \
/_/ |_| |_| \_\
|__\ |__\ |__\ |__\
标签:
原文地址:http://www.cnblogs.com/liaolongjun/p/4488306.html