chenlianxiang_Blog 2018-08-24 03:29 采纳率: 66.7%
浏览 1626
已采纳

HttpServletRequest取值

var params=
{
user_id:'1',
user_token:'',
charset:'',
format:'',
timestamp:'',
sign:'',
request_params:
{
project_id:'',
account_id:'110',
}
}
var obj=JSON.stringify(params);
var project_id=1;
$(function ()
{
$.ajax({
url:'api/account/get_account',
// url:'api/account/test',
type: 'POST',
dataType: 'json',
contentType: "application/x-www-form-urlencoded",
data:params,

@RequestMapping("/get_account")
public String get_account_list(HttpServletRequest request){

    // 公共入参
    int user_id = Integer.parseInt(request.getParameter("user_id"));
    String user_token = request.getParameter("user_token");
    String charset = request.getParameter("charset");
    String format = request.getParameter("format");
    String timestamp = request.getParameter("timestamp");
    String sign = request.getParameter("sign");
    String request_params = request.getParameter("request_params");
    System.out.println("request_params为:"+ request_params);

ajax请求,传递数据,HttpServletRequest如何取request_params的值 , request_params是一个对象

  • 写回答

5条回答 默认 最新

  • 玄尺 2018-08-24 03:43
    关注

    你应该这么改:
    1、将HTTP请求正文格式改成application/json,这样做的目的是将传递数据对象序列化成json字符串写到http请求正文中
    2、不要使用getParameter,这个方法你什么也拿不到,使用request读取正文数据转成字符串,这个字符串就是ajax发送的数据了

    当然可以使用框架简化代码。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?