SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    815
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    JSON / JSP problem..

    I never got an answer to my other post on similar problem.....
    http://www.sitepoint.com/forums/show...24#post4523224

    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...ndAJAXExamples

    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..

  2. #2
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    815
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ???????/

  3. #3
    SiteP0int Weazle hooknc's Avatar
    Join Date
    Dec 2004
    Location
    Socialist Republic of Boulder
    Posts
    937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    baby steps... baby steps...

  4. #4
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    815
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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..

  5. #5
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    815
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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/show...24#post4523224
    (it's like it's missing json.jar, but it's there...)

    thank you..

  6. #6
    SiteP0int Weazle hooknc's Avatar
    Join Date
    Dec 2004
    Location
    Socialist Republic of Boulder
    Posts
    937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    baby steps... baby steps...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •