By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,921 Members | 1,479 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,921 IT Pros & Developers. It's quick & easy.

integrate json in java

P: 46
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


Expand|Select|Wrap|Line Numbers
  1. <%@ page import="java.util.HashMap;" %>
  2. <%@ page import="java.util.Map;" %>
  3. <%@ page import="com.google.gson.Gson;" %>
  4.  
  5.  
  6. <%
  7.  
  8. Map<String, Object> map = new HashMap<String, Object>();
  9.  
  10. map.put("title", "event1");
  11. map.put("start","2009-11-11");
  12.  
  13.  
  14. // Convert to JSON string.
  15. String json = new Gson().toJson(map);
  16.  
  17. // Write JSON string.
  18. response.setContentType("application/json");
  19. response.setCharacterEncoding("UTF-8");
  20. response.getWriter().write(json);
  21. %>
and in my event page:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.  
  3.             $().ready(function() {
  4.                 $('#appdate').datepicker();
  5.                 $('#calendar').fullCalendar({
  6.                     dayClick : function(dayDate){
  7.                         var dates = dayDate.getDate();
  8.                         var months = dayDate.getMonth()+1;
  9.                         var years = dayDate.getFullYear();
  10.                         var newdate = years + "-" + months + "-" + dates;
  11.  
  12.                         document.location="../manageapp/slot.jsp?status=newslot&date="+newdate;
  13.                     },
  14.  
  15.                     events: "TemuDia-1.0/manageapp/getapp.jsp"
  16.                 })
  17.  
  18.             });
  19.  
  20.         </script>
anybody know how to integrate it
Jan 5 '10 #1
Share this Question
Share on Google+
5 Replies


Markus
Expert 5K+
P: 6,050
Line 16 should have a semi-colon at the end of it. See if this helps.
Jan 5 '10 #2

P: 46
sory..it doesn`t work
Jan 6 '10 #3

Frinavale
Expert Mod 5K+
P: 9,731
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
Jan 6 '10 #4

Markus
Expert 5K+
P: 6,050
Have you tried accessing the JSP page directly to make sure the Java is working correctly and outputting the JSON data.
Jan 6 '10 #5

P: 1
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(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
Map map = new HashMap();

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

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

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

// Write JSON string.
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json);
}


2- in your HTML or JSP

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

events: "/events"

});
Jun 22 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.