Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet is not getting data from front-end

 
Joe yaris
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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**

 
 
Rob Spoor
Sheriff
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
@Bear Bibeault and @Rob Spoor, I got my mistake. Thanks both of you!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic