• Post Reply Bookmark Topic Watch Topic
  • New Topic

can not post form data from JSP to servlet  RSS feed

 
jone kim
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to post form data from JSP page to servlet. I've put the logic inside doPost method. But when I click the submit button, the data is not posted in servlet class. Neither I am getting any error message in the console nor the System.out.println("Post method called..."); message is printed in the console. It seems that the doPost() method is not called when the submit button is pressed. I can not understand what is wrong with the code.

Servlet code

Web.xml file configuration
 
Mohammed Sardar.
Ranch Hand
Posts: 107
1
AngularJS Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

  I'm investigating this issue in detail to learn more but collapsed code with me .Can you just change the input type="button" to input type="Submit" then deploy to server and run to see how it goes ?

Thanks
 
jone kim
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot!!! When I changed the type to "submit" it solved the problem. But please can you explain why type="button" was not working?
 
Mohammed Sardar.
Ranch Hand
Posts: 107
1
AngularJS Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<input type="submit"> will submit the form when the user clicks on submit unless you specify otherwise with JavaScript. For in the below code input type is submit but it calls a function to check for valid login.

I hope below code gives more idea to understand.

<input type="submit" onclick="return validLogin();">  This deactivates the submit behaviour but validLogin() will get called upon requesting on the submit button.



<input type="button" /> buttons will not submit a form - they don't do anything by default. But of course it should work fine in our case
for the onclick="return validLogin();" though it's been declared as Submit.

Hope this helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!