Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ajax and JSON requests in jsp

 
Dhaval J. Patel
Ranch Hand
Posts: 90
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dhaval J. Patel
Ranch Hand
Posts: 90
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. I will try to implement SSL and remove unnecessary data :thumbup:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic