0

I have a jsp page where I am trying to get a JSON object from my servlet.

jsp code:

<%@page import="org.codehaus.jettison.json.JSONObject"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   "http://www.w3.org/TR/html4/loose.dtd">
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
 <title>View Json</title>
 <%
   JSONObject jsonObject=(JSONObject)request.getAttribute("jsonObject");
  %>
 </head>
 <body>
 <h6>JSON View</h6>
  <%=jsonObject%>
  </body>
 </html>

My java code sends the json object to the above jsp page:

 JSONObject jsonObj = new JSONObject(jsonString.toString());
 request.setAttribute("jsonObject", jsonObj);
 RequestDispatcher dispatcher = request.getRequestDispatcher("check.html");
 dispatcher.forward(request, response);

My jsp page is displaying all scriptlets instead of the json data. Please advice. Thanks.

I see this error in jsp page:

java.lang.ClassCastException: org.codehaus.jettison.json.JSONObject cannot be cast to org.json.simple.JSONObject
1
  • Try changing the page import to org.json.simple.JSONObject Commented Apr 10, 2016 at 7:34

1 Answer 1

1

Change import statement in jsp

From

<%@page import="org.codehaus.jettison.json.JSONObject"%>

to

<%@page import="org.json.simple.JSONObject"%>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.