码迷,mamicode.com
首页 > 其他好文 > 详细

Servlet中文乱码

时间:2015-05-08 18:04:26      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:

 

 

直接上代码

 

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"); 放在中间,前后输出来的中文都是乱码

 

 

 
                   .-‘ _..`.
                  /  .‘_.‘.‘
                 | .‘ (.)`.
                 ;‘   ,_   `.
 .--.__________.‘    ;  `.;-‘
|  ./               /
|  |               /
`..‘`-._  _____, ..‘
     / | |     | |\ \
    / /| |     | | \ \
   / / | |     | |  \ \
  /_/  |_|     |_|   \_\
 |__\  |__\    |__\  |__\

 

Servlet中文乱码

标签:

原文地址:http://www.cnblogs.com/liaolongjun/p/4488306.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!