简体   繁体   English

如何在XPage中从POST检索参数(java)

[英]How to retrieve parameters from POST in XPages (java)

I want to use Domino as a backend, and html/jquery as a frontend for my web application. 我想使用Domino作为后端,html / jquery作为我的Web应用程序的前端。 So I have: 所以我有:

$.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);
    }
});

In Domino: 在Domino中:

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";
}

In firebug and domino log I see that POST goes trough ok, gets the response. 在firebug和domino日志中,我看到POST正常,得到响应。 But I can't figure out how to get params f1 and f2 in domino. 但我无法弄清楚如何在多米诺骨牌中获得params f1和f2。 In domino log: 1) is null, 2) is null, 3) is 23. 在多米诺骨牌日志中:1)为空,2)为空,3)为23。

Idea for later is to POST JSON, but for now it would be great to have this code working. 以后的想法是POST JSON,但是现在让这段代码工作会很棒。

How to get POST parameters in domino via java? 如何通过java获取多米诺骨牌的POST参数?

(I see stackoverflow has a lot of similar questions answered, but couldn't find anything specific to my problem) (我看到stackoverflow有很多类似的问题得到解答,但找不到任何特定于我的问题)

Thank you! 谢谢!

Use reg.getReader() or req.getInputStream() to read the body of the request with elements f1 and f2. 使用reg.getReader()req.getInputStream()以元素f1和f2读取请求的主体。

Here is an example how you can read the JSON data: https://stackoverflow.com/a/3831791/2065611 以下是如何读取JSON数据的示例: https//stackoverflow.com/a/3831791/2065611

req.getParameter() works only if content type is "application/x-www-form-urlencoded", not json. req.getParameter()仅在内容类型为“application / x-www-form-urlencoded”而非json时有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM