• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

async JSP and servlet

 
Hendra Kurniawan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, I'm using jquery $.ajax. I'm wondering how to send ajax request to servlet every page load, and receive object (not json text) from servlet. what's the code in the servlet side and what's inside the success callback?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where's your code? What problems are you having with it? You should know by now that no one here is just going to do your work for you.

Hendra Kurniawan wrote:First, I'm using jquery $.ajax. I'm wondering how to send ajax request to servlet every page load,

If you're going to fetch on every page load, why bother with Ajax and why not just do whatever it is your doing on the server before the page is sent to the browser?

and receive object (not json text) from servlet.

You can't send objects in HTTP, you can only send text.

Again, if it's not text you need, why the Ajax? Why not deal with this on the server?
 
Hendra Kurniawan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need ajax to avoid page refresh. after some thoughts, it wouldn't make sense to place ajax call every page refresh. you got a point. But I just want to clarify, it's impossible to send object via ajax? absolutely impossible? text only? if so, does java have built-in lib to convert object to json?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no page refresh involved with pre-formating the page with JSP (or whatever you are using on the server).

After the page has been loaded, Ajax is used to avoid page reloads after user clicks and so on. But on page load, it's usually better to take of formatting the page on the server before it's sent to the client in the first place.
 
Hendra Kurniawan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and how about the json lib? java has built-in? or must use third party? if third party, what's your recommendation? thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well that's a bit of a non sequitor. But there are quite a number of fine JSON libraries available, but for various reasons I mostly use Google's Gson.
 
Hendra Kurniawan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GSON? java doesn't have built-in lib for this purpose?
 
Paul Clapham
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it doesn't.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic