开发者

Java Servlet req.getParameter("param") is null when querystring has 'ő' or 'ű' and if request is made by JQuery ajax

开发者 https://www.devze.com 2023-02-13 01:08 出处:网络
I have a very annoying problem With my Jquery based ajax live search. The search itself is working, but whenever my querystring contains \'ő\' and \'ű\' - only these two chars - , the value of the r

I have a very annoying problem With my Jquery based ajax live search. The search itself is working, but whenever my querystring contains 'ő' and 'ű' - only these two chars - , the value of the req.getParameter("sstring") is null! If the querystring does not have the mentioned chars, it returns the value successfully. I tried all possible encodings inluding UTF-8 but settled using 8859-2.

    $.ajax({
    type:"GET",
    url: "/myApp/Protected/getStd",
    contentType: "application/x-www-form-urlencoded; charset=iso-8859-2",
    dataType:"application/x-www-form-urlencoded; charset=iso-8859-2",
    data:"sstring="+escape(sstring)+"&options="+id+"&startrow="+startrow+"&valid="+Valid+"&notValid="+notValid+"&searchForm=1",

            async: true,
    success: function(data){
    $("#external").html(data);

    }
 })

I have to highlight that the pr开发者_如何转开发oblem only occures when the querystring is passed by Jquery. If I enter the QueryString to the browser manually the Servlet gets it properly. Any help is much appreciated.


As per the comments on the question:

INFO: sstring=min%u0151&options=1&startrow=0&valid=true&notValid=true&searchForm=1

The sstring parameter is not properly URL-encoded. You need encodeURIComponent() instead of escape().


Make the method POST.

type:"POST",

You don't say method is GET and yet pass the data as part of the body of the request. A GET request works purely based on URLs.

If you want to use GET, do this:

$.ajax({
    type:"GET",
    url: "/myApp/Protected/getStd?sstring="+escape(sstring)+"&options="+id+"&startrow="+startrow+"&valid="+Valid+"&notValid="+notValid+"&searchForm=1",
    async: true,
    success: function(data){
    $("#external").html(data);

    }
 })
0

精彩评论

暂无评论...
验证码 换一张
取 消