Link to home
Start Free TrialLog in
Avatar of Rohit Bajaj
Rohit BajajFlag for India

asked on

Handle form fields in spring mvc controller

HI,
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>

Open in new window


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;
    }

Open in new window


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;
    }
}

Open in new window



But when i submit the form all fields the in retention objects are null..

how do i handle it ?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Am P
Am P
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial