integrate json in java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • najmi
    New Member
    • Sep 2007
    • 46

    integrate json in java

    hai..

    i hava use FullCalendar in my application.i try to reload event into the calendar but it doesn`t work.here is my code


    Code:
    <%@ page import="java.util.HashMap;" %>
    <%@ page import="java.util.Map;" %>
    <%@ page import="com.google.gson.Gson;" %>
    
    
    <%
    
    Map<String, Object> map = new HashMap<String, Object>();
    
    map.put("title", "event1");
    map.put("start","2009-11-11");
    
    
    // Convert to JSON string.
    String json = new Gson().toJson(map);
    
    // Write JSON string.
    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().write(json);
    %>
    and in my event page:
    Code:
    <script type="text/javascript">
                
                $().ready(function() {
                    $('#appdate').datepicker();
                    $('#calendar').fullCalendar({
                        dayClick : function(dayDate){
                            var dates = dayDate.getDate();
                            var months = dayDate.getMonth()+1;
                            var years = dayDate.getFullYear();
                            var newdate = years + "-" + months + "-" + dates;
    
                            document.location="../manageapp/slot.jsp?status=newslot&date="+newdate;
                        },
    
                        events: "TemuDia-1.0/manageapp/getapp.jsp"
                    })
    
                });
    
            </script>
    anybody know how to integrate it
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Line 16 should have a semi-colon at the end of it. See if this helps.

    Comment

    • najmi
      New Member
      • Sep 2007
      • 46

      #3
      sory..it doesn`t work

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        What do you mean it "doesn't work"?
        Could you please supply more details on why it isn't working?

        Are you having problems handling the event in your JavaScript code, or in your Java code? Is the problem even to do with handling the event?

        What do you mean when you say "I tried to reload the event into the calendar"??


        -Frinny

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Have you tried accessing the JSP page directly to make sure the Java is working correctly and outputting the JSON data.

          Comment

          • razi99
            New Member
            • Jun 2010
            • 1

            #6
            Integrate json in java: Solution

            Hi

            I advise you to use Servlet

            1- dowload google jason for java
            - http://code.google.com/p/google-gson/downloads/list
            - use the gson-1.4.jar

            2- in java servlet
            this the code


            protected void doGet(HttpServl etRequest request, HttpServletResp onse response)
            throws ServletExceptio n, java.io.IOExcep tion {
            Map map = new HashMap();

            map.put("id", 111);
            map.put("title" , "event1");
            map.put("start" , new SimpleDateForma t("yyyy-MM-10").format(n ew Date()));
            map.put("url", "http://yahoo.com/");

            // Convert to JSON string.
            String json = new Gson().toJson(m ap);

            // Put json between [] to be formatted by Fullcalendar -- Ghazi
            json = "[" + json + "]";

            // Write JSON string.
            response.setCon tentType("appli cation/json");
            response.setCha racterEncoding( "UTF-8");
            response.getWri ter().write(jso n);
            }


            2- in your HTML or JSP

            var calendar = $('#calendar'). fullCalendar({

            events: "/events"

            });

            Comment

            Working...