0
我正在開發Web應用程序。
我從一個頁面發送json字符串到另一個頁面。 我已經使用jquery發送發佈數據。 在目標頁面中,我想檢索相同的數據。 但我在那裏得到null
值。request.parameter(String)從jquery調用時返回null
我的網頁,其中的帖子JSON字符串頁面:
$(document).ready(function() {
$.post("./ProfileUser.jsp",{jsonData:jsonstr});
$(location).attr('href',"./ProfileUser.jsp");
});
,並在頁面ProfileUser.jsp
<%
String jsonData = request.getParameter("jsonData");
String mobile;
if(jsonData == null) mobile = "something went wrong";
else {
JSONObject j =new JSONObject(jsonData);
mobile = j.getString("mobile");
}
%>
我得到輸出Something went wrong
這應該是從數據庫中的手機號碼。
我應該如何在jsp中獲取json數據?
謝謝
謝謝爲你的答案。這裏有什麼是響應的意義。我想在else塊中獲取json字符串的數據 –
這裏'request'參數是什麼''response''' request parameter' =>'HttpServletResponse Object' –
我已經試過了,正如你所說的,但問題存在 –