| Author |
Getting the javascript object(created in browser) as part of httservletrequest?
|
scott miles
Ranch Hand
Joined: Jun 16, 2011
Posts: 70
|
|
Lets say in a simple webapplication, i ceate a customerInfo javascript object(customerInfo.js) in js file and click createCutomer buttom on jsp. Assume that I have also mapped the the url mapping to sutomerservlet in web.xml. Two Questions on above
1) how i will get the customerInfo javascript object as part of my httservletrequest?
2) how can i convert that javascript object(assuming i will get as a string in httservletrequest) in to corresponding java object i.e customerInfo.java
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56179
|
|
1) You can't. Not directly.
2) You can either pass the individual elements as hidden parameters, or, if the objects have the exact same properties, serialize the object to JSON for transport.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
scott miles
Ranch Hand
Joined: Jun 16, 2011
Posts: 70
|
|
Thanks Bear Bibeault . As you said if the objects have the exact same properties, serialize the object to JSON for transport
Question on above point :- Assuming yours reference to json here as javascript object not the json java object
1) Does this conversion from simple javascript object to json needs to be done at client side?
2) Even if we do so, how we will get the this newly converted json at server side and then convert to java object ?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56179
|
|
1) Yes. There are plenty of tools to do so. Some modern browsers have JSON built in.
2) JSON is just a string. You can pass it to the server in a hidden input (or even on the URL, but not recommended). Once on the server, it can be de-serialized into a Java construct.
If we're only talking a handful of properties, using JSON might very well be overkill. It's much more customary to pass the properties individually.
|
 |
scott miles
Ranch Hand
Joined: Jun 16, 2011
Posts: 70
|
|
you mean to say that once we pass the jsonstring as hidden input(or as a part of URL) we can simply get it from httpservletrequest with the method getParameter("myJsonObjectName") and then convert to java object .Correct?
2)does the latest front end framewors like struts/dwr/ajax use the same kind of strategy internally?
3last question A you have referred the process of converting simple javascript object to json as serialization and then process of converting json to javaobject as deserialization. Jst Wonering in java when we say serialization it mean basically pesisting the state of javaobject.Is there any link b/w serialization term ypou used and standard java serialization/desializatioon process?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56179
|
|
1) yes
2) Ajax is not a framework. I have no idea if Struts or DWR have built-in JSON serialization.
3) No, nothing at all to do with Java.
|
 |
 |
|
|
subject: Getting the javascript object(created in browser) as part of httservletrequest?
|
|
|