当url包含非asciii字符时,HTTP 400错误请求

时间:2018-06-19 10:15:04

标签: javascript java spring internet-explorer

这是我的js文件,它将查询字符串参数传递给控制器​​。

function viewSelectedTravelerDetails(taNumber,country,city)
{
    // clearMessageBar();       
    if(taNumber != "")
    {
        var url = "travelerdetailview.htm?requestAction=viewTravelerDetails&taNumber="+taNumber+'&country='+country+'&city='+city;
        //var url = "travelerdetailview.htm?requestAction=viewTravelerDetails&taNumber="+taNumber;
        var windowName = "traveler_detail";
        var retValue = openNewWindow(url,windowName,"width=1024px,height=768px,center=1, status=0, titlebar=0, margin=0 auto,scrollbars=yes");
    }

}  

这是控制器方法,它处理上述请求的URL并在其他记录的情况下返回视图。

private ModelAndView handleTravelerDetailView(
      HttpServletRequest  request
    , HttpServletResponse response
    , Object              command
    , BindException       errors
) throws Exception {

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

    logIt.info( "Traveler city(ISO_8859_1):" + city );

    byte[] bytes = city.getBytes( StandardCharsets.ISO_8859_1 );

    city = new String( bytes, StandardCharsets.UTF_8 );

    logIt.info( "Traveler city(UTF-8):" + city );

    TravelerCO travelerViewData = migrateDataService.retrieveTravelerFullData( taNumber, country, city );

    logIt.info( "Traveler city(retrieveTravelerFullData):" + travelerViewData.getTravelerCity() );

    return new ModelAndView( getSuccessView(), getCommandName(), travelerViewData );
}

如果url包含非ascii字符(如

),则无法处理请求
  

travelerdetailview.htm requestAction = viewTravelerDetails&安培; taNumber = TA17 / 1246&安培;国家=安培;城市=

为什么我会收到400错误请求错误?请注意网址中的UTF-8字符。

0 个答案:

没有答案