Rohit Bajaj
asked on
Handle form fields in spring mvc controller
HI,
I have the following jsp :
And following controller method to handle this :
where retention is :
But when i submit the form all fields the in retention objects are null..
how do i handle it ?
Thanks
I have the following jsp :
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="/flock-retentions/policy" enctype="multipart/form-data" method="post">
<p>
Type some text (if you like):<br>
<input type="text" name="message" size="30">
</p>
<p>
Please specify a file, or a set of files:<br>
<input type="file" name="file" size="40">
</p>
<div>
<input type="submit" value="Send">
</div>
</form>
</body>
</html>
And following controller method to handle this :
@RequestMapping(value = "/policy")
public ModelAndView retentionPolicy(@ModelAttribute Retention retention, HttpServletResponse response, HttpServletRequest request) throws IOException {
ModelAndView mav = new ModelAndView("new");
return mav;
}
where retention is :
package org.yatra.code.model;
import org.springframework.web.util.HtmlUtils;
public class Retention {
private String id;
private String message;
private String file;
private String title;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public void parseHtml() {
message = HtmlUtils.htmlEscape(message);
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
But when i submit the form all fields the in retention objects are null..
how do i handle it ?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.