这是我的表格
<form id="profileChangeInput" action="" method="post">
<table border="0">
<tbody>
<tr>
<td class="profile_input_txt" align="right">First& nbsp;Name:</td>
<td><input type="text" id="fname"
name="j_firstname" value=""
class="profile_input_box_fname"></td>
</tr>
<tr>
<td class="profile_input_txt" align="right">Last Name:</td>
<td><input type="text" id="lname" name="j_lastname"
value="" class="profile_input_box_lname"></td>
</tr>
<tr>
<td class="profile_input_txt" align="right">ZIP Code:</td>
<td><input type="text" id="zip" name="j_zipcode"
value="" class="profile_input_box_zipcode"></td>
</tr>
<tr>
<td class="profile_input_txt" align="right">Phone #:</td>
<td><input type="text" id="phonenum"
name="j_phonenum" value=""
class="profile_input_box_phonenum"></td>
</tr>
<tr>
<td class="profile_input_txt" align="right">Year of Birth:</td>
<td><select id="selYOB">
<option value=""></option>
<option value="1950">1950</option>
<option value="1951">1951</option>
<option value="1952">1952</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
</select></td>
<td class="profile_input_txt" align="right">Gender:</td>
<td><select id="gender">
<option value=""></option>
<option value="male">Male</option>
<option value="female">Female</option>
</select></td>
</tr>
<tr>
<td class="profile_input_txt" align="right">Email Address:</td>
<td><input type="text" id="email" name="j_email"
value="" class="profile_input_box_email"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><input class="profile_btn" id="save_button"
type="submit" value="SAVE CHANGES"></td>
</tr>
</table>
这就是我尝试将其路由到控制器的方式
$.post('profileChange.do', $('#profileChangeInput').serialize(), function(data) {
alert('inside post:changes saved');
这是弹簧控制器
@Controller
@RequestMapping("/profileChange.do")
public class ProfileController {
@RequestMapping(method = RequestMethod.GET)
public String showProfile(@RequestParam(required=false) String rfky,Map model,HttpSession session){
ProfileInputDTO profileInputDTO = new ProfileInputDTO();
model.put("profileInputDTO", profileInputDTO);
System.out.println("in showprofile method");
return "myProfile";
}
@RequestMapping(method=RequestMethod.POST)
public @ResponseBody String ProcessProfileChange(ProfileInputDTO profileInputDTO,
BindingResult result,HttpSession session)throws Exception{
DataConverter dc = DataConverterUtil.getDefaultConverter();
WSOutputDTO output = ProcessProfileChange(profileInputDTO, session);
List<String> errors = output.errors;
if (errors == null) {
System.out.println("in success loop");
return "success";
} else {
String errorsStr = "";
for (String error : errors) {
errorsStr += error + "\n";
}
System.out.println("in errir loop");
return errorsStr;
}
}
});
答案 0 :(得分:0)
看起来您正在尝试提交ajax,如果是这样,请将ProfileInputDTO profileInputDTO
更改为@RequestBody ProfileInputDTO profileInputDTO
并删除BindingResult result