The scenario is I want to transfer my json object from my servlet to a jsp page and fetch the datas from json and display in jsp page.Please help.Thanks in advance.
Asked
Active
Viewed 1,276 times
1 Answers
0
You can do it using getAttribute()
which is for server-side usage only. You set an attribute in a servlet, and read it from a JSP. Can be used for any object, not just string.
Once you have called your servlet, you can simply set an attribute with your JSON object and then you can forward this request to your jsp page
request.setAttribute("jsonObject", jsonObject);
request.getRequestDispatcher("/WEB-INF/processor.jsp").forward(request, response);
And in your JSP page, get that JSON object and use it:
<%
JSONObject jo = (JSONObject) request.getAttribute("jsonObject");
out.println(jo.get("somekey"));
...
%>

Community
- 1
- 1

Raman Sahasi
- 30,180
- 9
- 58
- 71