• 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

Servlet is not getting data from front-end

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to submit form data from a html file using $.post method. But, in the server side, servlet is getting null. No field is empty and null. Can anyone tells me what is the issue? Thanks. BTW, I'm showing here just one field but actually I've several fields in the form. Thanks. Here is my code:

**html**

**JS**


**servlet**

**error in server side**

 
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) You don't have to check if your request is null. It won't be, as guaranteed by the servlet container.
2) You're actually sending your form data twice. Once through the JavaScript function, and once through the regular form submit. It's the latter that causes the error, because your input elements have an id, but no name, and the latter is used in form posts. You will have to make sure the HTML form submit is not finalized.
 
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
I've moved this to the HTML/JavaScript forum as the problems are in the JavaScript, not the servlet.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<input onclick="send()"
You shouldn't be using onclick at all. You are using jQuery, you should establish event handlers using jQuery not the onXXX attributes.

Moreover, you shouldn't be checking clicks at all -- you should listen for the submit event on the form, and be sure to return false from the event handler to prevent the "normal" form submission. >
 
Joe yaris
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Bear Bibeault and @Rob Spoor, I got my mistake. Thanks both of you!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic