File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Ajax and JSON requests in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Ajax and JSON requests in jsp " Watch "Ajax and JSON requests in jsp " New topic

Ajax and JSON requests in jsp

Dhaval J. Patel
Ranch Hand

Joined: Mar 10, 2011
Posts: 90

Hello Everyone,

I am here for some useful advice on how to use JSON with ajax.

I am trying to make a booking website. The back-end contains many javabeans that contain information about different aspects such as client information, booking information, location information etc. I am using JSON to serialize these beans and send them over to the client using AJAX. So basically making an ajax request and getting the serialized beans in response.

I have a complex object map (ie object A contains an instance of B as an instance variable, and B has objects C and D as instance variables and so on. All of these classes implement jsonaware interface. So when I put object A in the jsonobject everything inside it and the subsequent objects get into the object automatically. So it becomes easy when I want to send an object map.

But when I transmit that to the front end it contains extra information that I do not need for now . But in a way that promotes flexibility that in future if I need to display some data, I wont have to change the backend to transmit that data, instead just get it from the object that I have in javascript. But at the same time some beans have personal information which I need in some cases but in some cases I dont need it.

I want to know how to make sending out information through ajax using json safe. Is it secure if I use some kind of encryption algorithm to encrypt data being sent out. I am a newbie and do not have much experience with ajax. I am sorry if I am doing something terribly amateur here ..

My confusion is between manually picking what to put in the json object( that would increase the length of my functions and also would duplicate so much code) OR to implement jsonaware and send all the information to client but have some method of securing the data.

I hope to get some tough design lessons here :) Please help me on how to handle this situation

Thanks for your help in advance. I know its a big big question to read
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

Use SSL to protect any sensitive information in transit.

And I think that sending data that isn't needed "just in case it might be needed in the future" is not a good approach. Send just what is needed, and in the future, when you really know what additional data you'll need, then refactor to send just what you need.

[Asking smart questions] [About Bear] [Books by Bear]
Dhaval J. Patel
Ranch Hand

Joined: Mar 10, 2011
Posts: 90

Thanks for your reply. I will try to implement SSL and remove unnecessary data :thumbup:
I agree. Here's the link:
subject: Ajax and JSON requests in jsp
It's not a secret anymore!