0

I am trying to integrate json through a jquery ajax request in jsp. I am using org.json.simple package for this. Every thing is fine from client end, but from server response I am getting an 500 server code error, and 4 readyState code.

The response I am getting is:

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 12 in the generated java file
Only a type can be imported. org.json.simple.JSONObject resolves to a package

An error occurred at line: 15 in the jsp file: /interceptor_primaryengine_save.jsp
JSONObject cannot be resolved to a type
12: <body>
13: <%
14: 
15:   JSONObject obj = new JSONObject();
16:   
17:    String value = request.getParameter("value");
18:     obj.put("value",value);


An error occurred at line: 15 in the jsp file: /interceptor_primaryengine_save.jsp
JSONObject cannot be resolved to a type
12: <body>
13: <%
14: 
15:   JSONObject obj = new JSONObject();
16:   
17:    String value = request.getParameter("value");
18:     obj.put("value",value);


Stacktrace:

The jsp code I am using to send response is:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ page
    import="org.jdom.*,java.util.*,org.jdom.input.SAXBuilder,org.jdom.output.XMLOutputter,java.io.*,org.jdom.filter.*,org.json.simple.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>Insert title here</title>
</head>
<body>
<%

  JSONObject obj = new JSONObject();

   String value = request.getParameter("value");
    obj.put("value",value);
    out.print(value);
   out.flush();
  %>
</body>
</html>

I am using eclipse IDE. I have imported the jar file in the project. I have restarted server and restarted eclipse too. What am i doing wrong here?!

Maverick
  • 2,738
  • 24
  • 91
  • 157
  • Apart from the concrete problem, do you realize that you're mixing HTML with JSON here and that you're sending JSON as if it is HTML? A JSP is the wrong tool here. Rather use a servlet. For some examples, check this question: http://stackoverflow.com/questions/4112686/update-current-page-with-a-servlet – BalusC Apr 02 '11 at 21:00

1 Answers1

1

You can get that message if json-simple.jar is not found in the classpath in the webapp that is sending the response.

Evil E
  • 603
  • 1
  • 4
  • 10
  • I have copied the jar file inside the lib folder too. Do I have to set the classpath?! – Maverick Apr 02 '11 at 16:47
  • Sounds like you're on the right path. The jar file should be in the WEB-INF/lib directory. In Eclipse, right-click on the project and choose properties. Select the Libraries tab. You should see the jar file. If not, press Add JAR... and add it. The project should be deployed to your application server, which Eclipse may do for you if you have it set up correctly. – Evil E Apr 02 '11 at 20:30