简体   繁体   中英

JSTL c tag in javascript function

I'm trying to integrate jquery fullcalendar and mysql using spring mvc. I have to load schedule data from mySql and set the date into calendar. please show this :

<script type='text/javascript'>
            $(document).ready(function() {
                var calendar;
                var date = new Date();
                var y = date.getFullYear();
                var m = date.getMonth();
                var d = date.getDate();

                $('#calendar').fullCalendar({
                    header : {
                        left : 'title,prev,next today',
                        center : '',
                        right : 'month,agendaWeek,agendaDay' 
                    },
                    height: 650,
                    selectable: true,
                    select: function(start, end, allDay) {
                        var title = prompt('Event Title:');
                        if (title) {
                            calendar.fullCalendar('renderEvent',
                            {
                                title: title,
                                start: start,
                                allDay: allDay
                            },
                                    true // make the event "stick"
                                    );
                        }
                        calendar.fullCalendar('unselect');
                    },
                    editable : true,

                  events: [
                     <c:forEach var='event' items='${myData.events}'>
                         { title: '${event.title}', start: new Date (${event.timestamp}) },
                     </c:forEach>
      null // the trailling comma is  avoid the stray trailing comma.

    ];
                });

            });
        </script>

like this... is it possible? if so, How to use it ? and To integrate fullcalendar with DB, Do I have to only use php feed and Json , Ajax?? please help me.

you can simplify your things if you use library like GSON

In your controller use below code

    String jsonString = new Gson().toJson(ObjectList); // ObjectList is list of event object
    System.out.println(jsonString);
    request.setAttribute("eventsJson",jsonString); //setting  jsonString to request scope.

and in JSP

events: ${eventsJson}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM