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

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条)

报告相同问题?

悬赏问题

  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题