• 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

How to call Servlet using AJAX

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi first of all I want to mention that I am new to J2EE. I am working on a small project (using older style JSP's with scriplets only) for academic purpose. I am facing a problem that is as..

I have a form that is designed in a JSP. This form has 2 dropdown lists such that first one has fixed options and second one has to be populated dynamically (according to the option selected by user in first dropdown list) from the database (I am using Oracle). This is the task that I have to perform.

Now I am using a Servlet that is called by the form (JSP as discussed above) by means of AJAX (I am not comfortable with it at all). This Servlet further uses a DAO class to fetch the required values from the database. But I am unable to make the call for Servlet. However I have checked the Servlet by calling it separately & its working fine. I am making some mistake when calling the Servlet using AJAX. Please let me know what is the fault that has disappointed me for whole the day. I am attaching my JSP, Servlet & some other files also. Please help me to dig it out.

My code is as follows :-

JSP :-


Servlet :-


web.xml :-


Please any help would be greatly appreciated.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am making some mistake when calling the Servlet using AJAX.



What happens? Please be explicit.

Bill
 
S Chauhan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks William for the frequent reply.

My problem is 'how to call the servlet using AJAX'. I am making a mistake when calling the servlet from a JSP page using AJAX. Servlet is working fine. I am not able to resolve my mistake that I am making during servlet call.

Is there anything more to explain my problem ??
 
S Chauhan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
William ! I am not getting any response during servlet call, that's the problem.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A logical approach would be - instead of


Use an alert to show the actual xmlhttp.status. You are throwing away the information needed to see what is going on.

Is there any indication from the server that a request is being received at all?

Bill
 
S Chauhan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have resolved it.

William these alerts are just to check the flow of control as I am not going to use them in my project as it is.

My mistake was the URL that I was using in 'XMLHttpRequest.open()'. I have changed it to full url (like 'http://localhost:7001/.......') and I got the job done.

Thank you to come out for help.
 
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

S Chauhan wrote:I have changed it to full url (like 'http://localhost:7001/.......') and I got the job done.


That will not work as soon as you try to deploy the app.

You need to be using the server-relative URL that starts with the context path. See the ServletsFaq for more info.

 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic