Win a copy of Svelte and Sapper in Action this week in the JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Servlet is not hitting the request

 
Ranch Hand
Posts: 135
5
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
can anyone please point me out what i'm missing here? I haven't configured the web.xml. I think we can do without configuring that xml. According to the tutorial video i followed, he didn't talked a single word about web.xml. So i think we can call servlet without the help of web.xml. But i'm not sure. When i press submit, i don't get anything. at least the alerts that i have put. Please help me.







Thanks & Regards,
Jude
 
Marshal
Posts: 67449
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your JavaScript is not correct. (And as this is more about the JavaScript than the servlet, I've moved it to the HTML/JavaScript forum).

You should:
  • Foremost be using the jQuery forms plugin to simplify everything,
  • Put the URL to the servlet (don't forget the context path) in the form element's action attribute.
  • React to the submit event of the form, not clicks! (But using the Forms Plugin as outlined above means you won't need to even do this.)


  • Try refactoring using that information and lets see how far we get!
     
    Jude Niroshan
    Ranch Hand
    Posts: 135
    5
    Eclipse IDE Postgres Database Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks you very much for your reply. Now i resolved that JS errors and now i can see my alert messages. I didn't configure the web.xml and i didn't put the action attribute in form tag. I thought that my query part is handling that task, isn't it? When i click the submit, my request is not hitting to servlet. I'm sorry asking this kind of a simple question. But still i can't fix this thing.
     
    Bear Bibeault
    Marshal
    Posts: 67449
    173
    Mac Mac OS X IntelliJ IDE jQuery Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Have you fixed your code as suggested? Even if you do not want (for some unknown reason) to use the Forms plugin, responding to click events is outright wrong. What if the form is submitted in some other way? (Yes it can be.)

    I strongly recommend the plugin. But if you resist that, at least respond to the correct event.

    And, as I've already pointed out, your URL needs the context path.
     
    Jude Niroshan
    Ranch Hand
    Posts: 135
    5
    Eclipse IDE Postgres Database Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you sir... You saved my day....
    I have put the action and method inside the form tag an done the mapping in web.xml.

    But i have another simple problem. When i clicked the submit, my request goes to servlet and response is also coming. But the values in the JSON object is displaying in a white page. I wanted to capture those in my AJAX call and show them within my JSP. Could you please refer to my AJAX part and tell me my mistake there?
     
    Bear Bibeault
    Marshal
    Posts: 67449
    173
    Mac Mac OS X IntelliJ IDE jQuery Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    By putting the action in the form, you are likely not using Ajax at all -- which is why the response is appearing in the browser.

    You need to implement all my suggestions, not just one or two.

    Please refactor and post your new code.

    If you are not going to use the Forms plugin (which I highly recommend -- it should be a part of core jQuery it is so useful) then you must handle the submit event yourself.
     
    Jude Niroshan
    Ranch Hand
    Posts: 135
    5
    Eclipse IDE Postgres Database Java
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    @Bear Bibeault
    Sir,
    You saved my life. Now I am using the jquery form plugin for ajax calls. That is really awesome. Thank you again. Could you please show me an example where i want to send a textfield value before clicking to submit button?
    This is basically, i want to check whether the entered email address is already registered one or not. I have done it using traditional ajax way. But i wonder whether i can use this ajax form plugin. I looked into their API. results were negative. Appreciate your help.
    Regards,
    Jude
     
    Bartender
    Posts: 1810
    28
    jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Jude Niroshan wrote:Could you please show me an example where i want to send a textfield value before clicking to submit button?


    You could use the jQuery ".blur()" function. Bind that to the email input field and when the user tabs out of the email field or clicks away from it, you can fire off an Ajax query to see if the email already exists. If it does, you could move the focus back to the email field and ask for a different address or whatever response is correct for your application.
      Bookmark Topic Watch Topic
    • New Topic