Linux环境下对URL中汉字参数的处理!

Linux环境下对URL中汉字参数的处理!

在linux下传递汉字参数和windows下不同,需要进行encode和decode处理,例如
http://wap.lenovomobile.com/weather/deurl.do?city=%E5%8E%A6%E9%97%A8

%E5%8E%A6%E9%97%A8 就是对厦门作了 encode 处理后才发送出来的请求,而不是直接带“厦门”这两个汉字

下面是对这个请求的处理,实现一个简单的转发
 static String kongPrefix = "http://kong.net:80/weather/generallenovo.jsp?city=";

    static String kongcity = "010";

    // 包装联想搜索页的关键字和url
    public ModelAndView handleRequest(HttpServletRequest request,
                                      HttpServletResponse response) throws Exception {
        response.setCharacterEncoding("utf-8");

        String city = request.getParameter("city");

        if (Helper.isNull(city)) {
            city = kongcity;
        } else {
            //city = new String(city.getBytes("ISO-8859-1"), "UTF-8");
            city = URLDecoder.decode(city, "UTF-8");
            city = URLEncoder.encode(city, "UTF-8");
        }

        String url = "";

        url = kongPrefix + city;

        response.sendRedirect(url);
        return null;
    }

你可能感兴趣的:(linux,jsp,windows,.net,WAP)