add_person.jsp

<body>
  <form name="frmTest" id="frmTest" method="post" action="/Test2/Control1/displayPerson">
    <input type="text" name="Name" />I Agree
	<select name="Location">
  	  <option value="Teynampet">Teynampet</option>
	  <option value="TNagar">TNagar</option>
	  <option value="Adyar">Adyar</option>
	</select>
    <input type="checkbox" name="cboAgree" value="I Agree"/>I Agree		
    <input type="submit" name="btnSubmit" value="Submit"/>		
  </form>
</body>

Person.java

public class Person 
{
	private String Name;
	private String Location;	
	
	public String getName() {
		return Name;
	}
	public void setName(String name) {
		Name = name;
	}
	public String getLocation() {
		return Location;
	}
	public void setLocation(String location) {
		Location = location;
	}

        @Override
	public String toString() 
        {
	  return "Person [Name=" + Name + ", Location=" + Location + "]";
	}
}

TestController .java

@Controller
@RequestMapping("/Control1")
public class TestController 
{
	@RequestMapping(value="/displayPerson", method=RequestMethod.POST)
	public String TestMe4(@ModelAttribute Person person)
	{
		System.out.println(person); 
		return "add_person";
	}
}

Output

Person [Name=Mac, Location=TNagar]

Comments are closed.