Loading ...
Sorry, an error occurred while loading the content.

1019Re: [json] Sharing Java objects with JavaScript

Expand Messages
  • Claudio D'angelo
    May 15, 2008
      HI Phil,
      If I've understood you have a servlet that supply the information used
      to choice if build a select and (eventually) setted it.

      You have more choices but I tell you only two:

      * In the servlet you can use the HttpServletResponse to write in
      output the json stream:

      protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
      String response = ....; // the json string , i.e:
      {select:true, values:[{value:"xxx", label:"Label 1"}, ...]}
      PrintWriter writer = resp.getWriter();

      P.S.: you can use a JSP too.

      In javascript you receive the object directly.

      * You can also use the JAJB (http://jajb.sourceforg.net) that is a
      binding system between java and json. You can have in java your
      javabean and map it in json stream (and vice versa). If you don't
      want think about transmission you can use the JsonRPC for java
      (you can found it in http://jontools.sourceforge.net but is in
      development status although it works) that use JAJB to map json to
      java and call directly your business class.

      If I can help you, let me know.

      Phil ha scritto:
      > I'm upgrading a web page so that it uses ajax. I'm pretty much done,
      > except for one thing. If I have a value determined in a servlet that I
      > need to use in JavaScript how can I use JSON to do this for me? EG; I'm
      > setting a value in the servlet that controls whether or not I build a
      > SELECT control in JavaScript using the DOM methods. How do I access
      > that value in the JS?
      > TIA...
      > [Non-text portions of this message have been removed]
    • Show all 12 messages in this topic