The post ajax request parameter acquisition not a problem on the server

The contentType Ajax post request if the attribute is "application / x-www-form-urlencode", while if "application / json", HttpServletRequest implementation class not resolve data in the form of the request parameter map, so by request.getParameter how ( "XX") are also not receiving data. code show as below:

js code:

function newFunc(){

  var params = {};

  params.aa = ‘XX’;

  $.ajax({

    async:false,

    contentType:'application/json',

    url:projectUrl+'chk/ajax/ChkMessage.xhtml',

    type:'post',

    data:params,

    dataType:'json'

  });

}

java code:

@RequestMapping("/{channel/ChkMessage.xhtml}")

public void chkUserMessage(HttpServletRequest request,HttpSerlvetResponse response){

  Request.getParameter AA = String ( "AA"); // AA here is null

}

 

Solution:

① ajax into the get request;

②contentType does not use "application / json".

Guess you like

Origin www.cnblogs.com/24ming/p/12009362.html