为什么带有特殊字符的字符串在GET和POST方法中表现不同?

时间:2019-05-22 13:33:20

标签: javascript java jquery ajax

通过使用jQuery,我试图将我的字符串数组保存在后端,这是我的方法。

1。使用jQuery ajax发送数组。

SET _ROOT = D:\Qt\src
SET PATH = %_ROOT%\qtbase\bin;%_ROOT%\gnuwin32\bin;%PATH%
configure -static -static-runtime -release -platform win32-msvc - opensource -confirm-license -nomake examples -nomake tests -prefix 
D:\Qt\build
jom
jom install

2。在后端按以下方式检索:

var tagTexts = $(ul li.select2-selection__choice")
                   .toArray()
                   .map(function(i){
                       return i.innerText;
                   });
tagTexts = JSON.stringify(tagTexts);
$.ajax({
    type: 'POST' ,
    url: '/tag/tagList',
    dataType: 'json',
    data: {
        tagTexts: tagTexts
    },
    error: function(err) {
       console.log(err);
    },
    success: function(response) {
        //Process Response
    }

});

在这种情况下,一切正常。

使用GET选项尝试相同的方案:

我已经尝试过使用@ResponseBody @RequestMapping(value = "/tag/tagList", method = RequestMethod.POST) public String saveTagList(HttpServletRequest request, @RequestParam(value = "searchTagTexts", required = false)String tagListString) { try { List<String> tagTexts = (List<String>)mapper.readValue(tagListString, new TypeReference<List<String>>() {}); System.out.println(tagTexts); String response = tagService.saveTags(tagTexts); return response; } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } 选项的上述情况(例如在ajax调用中添加类型:'GET',并在@RequestMapping批注中设置方法= RequestMethod.GET)。

在进行ajax调用时,以下将是 tagTexts 的值:

GET

在Java执行(后端)中,其显示如下:

enter image description here

我在后端收到了意外的字符串。这种行为的原因是什么?

0 个答案:

没有答案