Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get data from a HTML form in Spring MVC Controller?

 
Anupam Dee
Ranch Hand
Posts: 42
Firefox Browser Tomcat Server Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to Spring MVC.
I am facing a simple problem but unable to understand how to do it.
I have a simple form containing an input field and a submit button. All i have to do is to enter the userid in the field and hit enter.. and the user with that id shows up.

But how to get the request parameters in the Controller class ?
i am not able to understand the @ModelAttribute annotation also..
Why should we use this annotation?
Please help me.

Thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This example from the Spring tutorial shows using the @RequestParam annotation to map HTML form parameters to the method signature. In this case, "petId" is the name of the field on the HTML form.

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anupam Dee wrote: am not able to understand the @ModelAttribute annotation also..

Missed this on first read. This thread explains it well.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
 
Sindhu Kodoor
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done a POC today by following this one :
http://www.mkyong.com/spring-mvc/spring-mvc-form-handling-annotation-example/
hope it benefits you !
 
Anupam Dee
Ranch Hand
Posts: 42
Firefox Browser Tomcat Server Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you everyone.
I still have a lot of confusions. But I ll ask them one by one and get them clear.
Thanks once again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic