0

I am using json-lib-0.9.jar. in view.class i am getting inputstream from the request, setting into request and dorwarding request to Render.jsp, i am not able to understand how to fix this. could someone help me in in order to fix this issue. thanks in advance

View.class

  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import net.sf.json.JSONObject;
     private void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException { {                 
            if (request.getInputStream() != null) {
               byte[]   bytes = IOUtils.toByteArray(request.getInputStream());    
            String resString=new String(bytes, StandardCharsets.UTF_8);
            JSONObject Json  = JSONObject.fromString(resString);   
            request.setAttribute("META", Json.get("META"))              
     }
      request.getRequestDispatcher("/jsp/Render.jsp").forward(request, response);
 }

Render.jsp

<%@page import="net.sf.json.JSONObject" %>
<%
JSONObject docMeta =  (JSONObject)request.getAttribute("META");%>

in this line its throwing

java.lang.ClassCastException
java.lang.ClassCastException: net.sf.json.JSONObject cannot be cast to net.sf.json.JSONObject
at org.apache.jsp.jsp.Render_jsp._jspService(PreviewLander_jsp.java:134)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:71)
4
  • maybe you are using two different versions of the library. have you tried looking at the dependency tree to see if there are conflicting versions somewhere? Commented Nov 8, 2021 at 13:20
  • its dependency has different version jar Commented Nov 8, 2021 at 13:55
  • then there's your problem. on the dependency, apply an exclude Commented Nov 8, 2021 at 13:57
  • Yes. This is caused by loading different versions (or the same version) of a class on two different classloaders. The Java runtime system say they are different classes. Commented Nov 8, 2021 at 14:42

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.