protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String title = request.getParameter("title");
String timelength = request.getParameter("timelength");
System.out.println("视频名称:" +title);
System.out.println("视频时长: "+timelength);
response.getWriter().write(title);
}
这样,我在浏览器输入:
http://localhost:8080/weba/newsmanager?title=%B5%C4%B5%C4%B5%C4&timelength=121
(这里有例外一个问题,我输入的中文,结果被转换成了这么一串字母。这是为何呢,我使用的是火狐浏览器)
但是控制台打印出的信息,浏览器界面显示的信息,都是乱码。
我已经将浏览器的编码设置成了utf-8。
------解决方案--------------------
控制台:
System.out.println("视频名称:" +new String(title.getBytes("iso-8859-1"),"utf-8"));
浏览器端编码设成utf-8