java - 如何从 XPages (java) 中的 POST 检索参数

标签 java jquery post parameters xpages

我想使用 Domino 作为后端,使用 html/jquery 作为我的 Web 应用程序的前端。所以我有:

$.ajax({
    type: 'POST',
    url: 'mydb.nsf/xpage.xsp',
    contentType: 'application/json; charset=utf-8',
    data: { 
        f1: "hello", 
        f2: "hello again"
    },
    success: function (response) {
        console.log("SUCCESS");
    },
    error: function (error) {
        console.log(error);
    }
});

在多米诺中:

public static String doGet(HttpServletRequest req, HttpServletResponse res) throws JsonException, IOException, NotesException {
    return doPost(req, res);
}    

public static String doPost(HttpServletRequest req, HttpServletResponse res) throws JsonException, IOException, NotesException {
    System.out.println("1) "+req.getAttribute("f1"));
    System.out.println("2) "+req.getParameter("f1"));
    System.out.println("3) "+req.getContentLength());

    return "AllOK";
}

在 firebug 和 domino 日志中,我看到 POST 正常运行,得到响应。但我不知道如何在多米诺骨牌中获取参数 f1 和 f2。 在多米诺骨牌日志中: 1) 为空, 2)为空, 3) 是 23。

稍后的想法是 POST JSON,但现在让这段代码正常工作会很棒。

如何通过java获取domino中的POST参数?

(我看到 stackoverflow 已经回答了很多类似的问题,但是找不到任何针对我的问题的具体问题)

谢谢!

最佳答案

使用 reg.getReader()req.getInputStream() 读取包含元素 f1 和 f2 的请求正文。

这是一个如何读取 JSON 数据的示例: https://stackoverflow.com/a/3831791/2065611

req.getParameter() 仅在内容类型为“application/x-www-form-urlencoded”而非 json 时有效。

关于java - 如何从 XPages (java) 中的 POST 检索参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36081659/

相关文章:

java - Java中如何解决这个 "non-static variable"问题?

java - View 中的动画列表

javascript - jQuery:添加基于内联条件的内联函数调用......这可能吗?

php - 使用fsockopen进行PHP GET和POST数据

python - 使用 python requests 和 json 发布文件

java - 如何修复 "if"始终变为 "true"

java - 有选择地删除eclipse中的方法

php - SyntaxError : JSON. 解析:意外字符

javascript - 循环遍历表行的性能问题

javascript - 在 Node.js 中使用 PUT 删除