[英]How to retrieve parameters from POST in XPages (java)
我想使用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);
}
});
在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";
}
在firebug和domino日志中,我看到POST正常,得到响应。 但我无法弄清楚如何在多米诺骨牌中获得params f1和f2。 在多米诺骨牌日志中:1)为空,2)为空,3)为23。
以后的想法是POST JSON,但是现在让这段代码工作会很棒。
如何通过java获取多米诺骨牌的POST参数?
(我看到stackoverflow有很多类似的问题得到解答,但找不到任何特定于我的问题)
谢谢!
使用reg.getReader()
或req.getInputStream()
以元素f1和f2读取请求的主体。
以下是如何读取JSON数据的示例: https : //stackoverflow.com/a/3831791/2065611
req.getParameter()
仅在内容类型为“application / x-www-form-urlencoded”而非json时有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.