• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

AJAX and Servlet parameter issue

 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't have the code with me, but it's simple enough to explain accurately.


I have a Form, with an Input. The Form does not have the Action attb. The Input calls a JS method, which in turn calls the servlet.

Everything works for this process...servlet is called, etc etc.

When I have the Form with the Action attb filled in, not using AJAX at all, in the servlet I can call request.getParamter("div-tag-name");

However, since I don't have the Action on the Form, i'm not able to get a Div name using the Ajax to call the servlet. This is true for both GET and POST.

How can I use Ajax to call POST on the servlet and still be able to use request.getParameter("div-name") in the servlet? When I do it now it's just null...i assume Ajax doens't send this info. I have tried in the JS method to do the setRequestHeader('content-type.....,'etc etc') and send("div-ID-name"), but still getParameter() in the Servlet is null...

what am i supposed to do to fix this???
[ January 26, 2008: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67746
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
When making the Ajax call, are you passing it the value?

You might want to look through this article for how to pass params through XMLHttpRequest.
 
Michael Raymond Jr.
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
When making the Ajax call, are you passing it the value?

You might want to look through this article for how to pass params through XMLHttpRequest.



yes


and, i don't see anything in the article except the send() method, and I've tried that.

if that's the only way to send data with the Post (using send()), then i think the Ajax part is correct and this is probably a Java issue...not knowing how to retrieve the data from the JS send() method essentially.

argh...
 
Bear Bibeault
Sheriff
Posts: 67746
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 are sending the parameter info correctly in the Ajax call, there will be no difference in the way that the servlet handles it. It's just an HTTP request like any other.

I think it's time to show us your Ajax code. Please be sure to use UBB code tags.
 
Bear Bibeault
Sheriff
Posts: 67746
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
And... as Eric and I have said many times in this forum, using raw Ajax at this point is a needless hassle. There are many nuances that are easy to get wrong.

Use a library such as Prototype or jQuery to do your Ajax for you. Generally, you can replace dozens of lines of code with a single statement that makes sure that everything happens correctly.

For example, using jQuery and its form plugin, you would add your servlet URL to the form's action attribute and then you could say:

Your form and all its parameters will be submitted via Ajax. Correctly. It doesn't get any easier than that.
[ January 26, 2008: Message edited by: Bear Bibeault ]
 
Michael Raymond Jr.
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
If you are sending the parameter info correctly in the Ajax call, there will be no difference in the way that the servlet handles it. It's just an HTTP request like any other.

I think it's time to show us your Ajax code. Please be sure to use UBB code tags.



thanks for the response. i couldn't post code until now, but decided to take antoher stab at it before posting now that i got some sleep.

everything was right, EXCEPT that in my send() i wasn't equating the paramter name to a value. for instance, i had

send("divName") but should've had

send("divName=blahValue");

i looked at it a 100 times and just didn't see it!!!
 
Bear Bibeault
Sheriff
Posts: 67746
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
Never underestimate the recuperative powers of sleep!

Glad it's working for you now.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
Never underestimate the recuperative powers of sleep!

Glad it's working for you now.



Bear does not sleep..he hibernates..

With Bear's comment. Using Librarie or toolkits thta use Ajax is the best [well if it is a good library or toolkit] because thy handle a lot of browser quirks in the XHR that you may never see until it is too late.

Things such as why do I nee try catch around the activeX call or around status, what t do with 12XXX errors and so on.

Eric
 
Bear Bibeault
Sheriff
Posts: 67746
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic