[英]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.