JSON / JSP problem

I never got an answer to my other post on similar problem…

now trying another example… basically am trying to make an ajax request with JSON/JSP, not succeeding… now found another example here:
http://code.google.com/p/json-simple/wiki/JSPAndAJAXExamples

which I’m trying to run here:

http://www.mayacove.com/ajax/json_google.html

but the “something went wrong” code is triggered…

JSP:

<%@page contentType=“text/html; charset=UTF-8”%>
<%@page import=“org.json.simple.JSONObject”%>
<%
JSONObject obj = new JSONObject();
obj.put(“name”,“foo”);
obj.put(“num”,new Integer(100));
obj.put(“balance”,new Double(1000.21));
obj.put(“is_vip”,new Boolean(true));
obj.put(“nickname”,null);
out.print(obj);
out.flush();
%>

what is the problem, please…

(not sure if this a JSP or an AJAX problem, sorry for posting here if it’s an ajax problem…)

thank you…

???/

I wouldn’t try to do the type of work you’re doing in a JSP. Consider using a servlet or action or controller (depending on the web framework you’re using).

Btw, I don’t see any reason for the code above not to work, but you most likely shouldn’t be calling flush yourself. I’m fairly certain that the JSP will try to flush the content it self when it is done.

really? hmmm… was just trying to make example here,
http://code.google.com/p/json-simple...ndAJAXExamples
work, which as you can see, has a JSP…

I do know servlets, but they are a pain b/c every time I compile a servlet I have to restart the server (tomcat 5.5) this is a huge pain, and not practical at all when you’re just doing a learning exercise… (or in any other situation…)

so why do you say I should do this in a servlet and not a JSP?

thank you…

Btw, I don’t see any reason for the code above not to work, but you most likely shouldn’t be calling flush yourself. I’m fairly certain that the JSP will try to flush the content it self when it is done.[/QUOTE]

hmmm… this is how orig example is…
http://code.google.com/p/json-simple...ndAJAXExamples

(I took out ‘out.flush’ line… but still get same result…)

this is frustrating… the two JSON/JSP examples I have found online I can’t make work (this one http://www.learn-ajax-tutorial.com/Json.cfm#h1.2 also doesn’t work… get errors as described in this thread:
http://www.sitepoint.com/forums/showthread.php?p=4523224#post4523224
(it’s like it’s missing json.jar, but it’s there…)

thank you…

Do you get a stacktrace? The “Something went wrong” isn’t very helpful…

It looks like the JSPAndAJAXExamples page has its own jar that needs to be in your WEB-INF/lib directory. It looks like the name is json_simple-1.1.jar. Which is different then the json.jar.