我想使用 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/