Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Pass object to frontend using servlet and ajax

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Can someone suggest me on how to pass the object from the server side(servlet) to the jsp.Precisely.i have a form having a textfield for entering a person's name and a 'process' button.I have called a js function (using ajax) on the click of the button,the persons name goes to the server and fetches information like,organization,date of birth and a String array( having the names of the person who work under him).The object information is displayed correctly in the servlet.Now how do i pass the bean object(organization,dob,stringarray) into the js function and display the information in the jsp.i tried request setattribute and getattribute but i am not sure whether it works on onclick of a button.Is JSON something which i should look upon.Someone guide me please.

Thanks in advance
Ajay
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There should be plenty of Java libraries out there that will take an object and form it into a JSON object.

Eric
 
Sheriff
Posts: 67636
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
If you use jQuery for your Ajax, the $.getJson() method will automatically reconstruct a client-side object from a JSON response (which I create on the server using the Gson library).
 
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic