日期:2014-05-16 浏览次数:20379 次
<a href="Test?method=河南省郑州市">测试</a> //servlet public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html"); PrintWriter out = response.getWriter(); String method=request.getParameter("method"); method=this.convert(method); out.print(method); System.out.println("编码转换之后:"+method); out.flush(); out.close(); } //编码转换方法 public String convert(String target){ System.out.println("编码转换之前:" + target); try { return new String(target.trim().getBytes("ISO-8859-1"),"UTF-8"); } catch (UnsupportedEncodingException e) { return target; } }