473,386 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

integrate json in java

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
5 6688
Markus
6,050 Expert 4TB
Line 16 should have a semi-colon at the end of it. See if this helps.
Jan 5 '10 #2
najmi
46
sory..it doesn`t work
Jan 6 '10 #3
Frinavale
9,735 Expert Mod 8TB
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
6,050 Expert 4TB
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
razi99
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

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

Similar topics

16
by: G Matthew J | last post by:
http://htmatters.net/htm/1/2005/07/evaling-JSON.cfm This is more or less in response to Mr Crockford's admonition a few months ago, "fork if you must". Ironically, although in that usenet post...
20
by: Luke Matuszewski | last post by:
Welcome As suggested i looked into JSON project and was amazed but... What about cyclical data structures - anybody was faced it in some project ? Is there any satisactional recomendation... ...
10
by: Frank Millman | last post by:
Hi all I am writing a multi-user accounting/business application, which uses sockets to communicate between server and client. The server contains all the business logic. It has no direct...
2
by: phil.swenson | last post by:
I'm using Prototype.js and would like to convert the contents of an HTML table to JSON. Converting to an array first is fine too. Any thoughts on this? I haven't seen anyone do anything this.......
23
by: dhtmlkitchen | last post by:
JSON We all know what it is. In ECMAScript 4, there's a JSON proposal: Object.prototype.toJSONString String.prototype.parseJSON The current proposal, String.prototype.parseJSON, returns...
4
by: im12345 | last post by:
I have the following question: Im doing a sample application using dojo and json. I have 2 classes: 1. Book class package com.esolaria.dojoex; import org.json.JSONObject; import...
1
by: valheru | last post by:
Hi, I'm not sure if this question even makes sense, so bear with me here. I'm using a tool called HtmlUnit (which is like JUnit) to send a http request to my web application. The http address...
1
by: Max | last post by:
Douglas Crockford ha scritto: Thank you Douglas. I hope to find a solution to implement a Javascript converter from XML to JSON. (Pay attention to page examples on json.org because there are...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.