• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Getting the javascript object(created in browser) as part of httservletrequest?

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
scott miles
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
What's that smell? Hey, sniff this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic