我想提交一个包含上传文件字段的表单。当我点击提交按钮时没有任何反应。
我的前端和后端代码如下。
CharSequence error = ((TextInputLayout) view).getError();
配置文件
<form:form action="${url}profile/edit" method="post"
modelAttribute="profile" role="form"
enctype="multipart/form-data">
<div class="form-group">
<label for="photo">Photo</label> <input type="file"
name="photo" class="form-control" id="photo">
</div>
<div class="form-group">
<label for="title">Title</label>
<div class="dropdown dropdown-form">
<a class="shape-arrow" href="#" data-toggle="dropdown"><span></span></a>
<input type="text" name="title" id="title"
class="form-control" data-toggle="dropdown"
autocomplete="off">
<ul class="dropdown-menu" role="menu" aria-labelledby="title">
<li><a href="#" rel="nofollow">Male</a></li>
<li><a href="#" rel="nofollow">Female</a></li>
</ul>
</div>
</div>
<div class="form-group">
<label for="firstName">First Name</label> <input type="text"
name="firstName" class="form-control" id="firstName">
</div>
<div class="form-group">
<label for="lastName">Last Name</label> <input type="text"
name="lastName" class="form-control" id="lastName">
</div>
<div class="form-group">
<label for="email" class="control-label">Email</label>
<div class="input-group">
<span class="input-group-addon">@</span> <input type="email"
id="email" name="email" class="form-control"
placeholder="Enter email">
</div>
</div>
<div class="text-center">
<button class="btn btn-action btn-save">Save</button>
</div>
</form:form>
RequestHandler
public class Profile {
private MultipartFile photo;
private String title;
private String firstName;
private String lastName;
private String email;
getters and setters
}
我添加了&#39; Type&#39;归因于&#39;按钮&#39;但是还不能提交表格。
@Controller
@RequestMapping("/profile")
public class ProfileController {
@RequestMapping(value = "/edit", method = RequestMethod.POST)
public String editProfile(
@ModelAttribute("profile") Profile profile, Model model) {
System.err.println("in profile/edit" + profile);
return "profile";
}
}
另外,我更改按钮输入无效。
<button class="btn btn-action btn-save" type="submit">Save</button>