I need send a form from php to java using the method post and curl. I'm having problems to fetch a list of objects in php when I submit the form. I would like to know if is possible to do it like in Spring MVC (specifying attribute name in the form)
<form method="post" action="group_create.php">
<div>
Name: <input type="text" name="name" />
<br />
<input type="text" name="users[0].name" value="753" />
<br />
<input type="text" name="users[1].name" value="752" />
<br />
<input type="submit" value="Save" />
</div>
</form>
Encoding method:
<?php
http_build_query($_POST);
?>
Current curl url:
javaserver/app/groups/create?name=Administrator&users[0]=Tom&users[1]=Myke
Necessary curl url:
javaserver/app/groups/create?name=Administrator&users[0].name=Tom&users[1].name=Myke
My DTO's:
public class GroupDTO {
private String name;
private List<UserDTO> users;
public GroupDTO()
{
this.users = new ArrayList<UserDTO>();
}
}
public class UserDTO {
private String name;
}
Spring MVC Controller:
@Controller
@RequestMapping("secure/groups")
public class GroupsController {
@RequestMapping(value = "create", method = RequestMethod.POST)
public @ResponseBody ModelMap create(GroupDTO dto)
{
ModelMap map = new ModelMap();
//CODE TO DO ANYTHING
return map;
}
}
Change this:
<form method="post" action="group_create.php">
<div>
Name: <input type="text" name="name" />
<br />
<input type="text" name="users[0].name" value="753" />
<br />
<input type="text" name="users[1].name" value="752" />
<br />
<input type="submit" value="Save" />
</div>
</form>
To this:
<form method="post" action="group_create.php">
<div>
Name: <input type="text" name="name" />
<br />
<input type="text" name="users[0]" value="753" />
<br />
<input type="text" name="users[1]" value="752" />
<br />
<input type="submit" value="Save" />
</div>
</form>
The ".name" part is not needed for the form to operate properly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.