0

I have one Controller : personController.java

@Controller 
public class personController {     

    private static final Logger LOG = LoggerFactory.getLogger(OcaController.class);  

    @RequestMapping(value = "/person", method = {RequestMethod.POST, RequestMethod.GET})        
    public String ocaContract(@RequestBody String requestPerson) {
        return requestPerson;
    }    

1 JSP : person.jsp

<html>
    <head>
    </head>
    <body>
        <form class="form-horizontal" METHOD="POST" ACTION="webmvc/person" ENCTYPE="x-www-form-urlencoded">
            <div class="controls">
                <input type="text" name="name" id="name" value="" placeholder="">
            </div>
            <div class="controls">
                <input type="text" name="surname" id="surname" value="" placeholder="">
            </div>
            <input type="submit" value="ok"/>
        </form>
    </body>
</html>

and one Object Class : Person.java

@XmlRootElement(name="Person")
public class Person {

@XmlElement(required = true)
protected String name;
@XmlElement(required = true, nillable = true)
protected String surname;

 public String getName() {
    return name;
}

public void setName(String value) {
    this.name = value;
} ...

When I populate the JSP and click on the input button, my controller return this "requestPerson" string :

name=&surname=

Is it a way to have this string as a POJO ? My final result must be at the XML format :

<person>
<name>Lisala</name>
<surname>Lili</surname></person>

I hope you ll can help me because i'm on it since 1 day now and i didn't find an easy way to accomplish this.

4
  • This is nullable= true a typo in :@XmlElement(required = true, nillable = true) Commented Mar 22, 2016 at 7:59
  • xjc generate this code... I think it doesn't matter Commented Mar 22, 2016 at 8:03
  • So your question is how to replace String with Person? Commented Mar 22, 2016 at 13:24
  • Yes but I have Error HTTP 415 - when I try to replace String by Person... Commented Mar 22, 2016 at 16:02

1 Answer 1

1

You can replace @RequestBody with @ModelAttribute and String to Person

public String ocaContract(@ModelAttribute Person requestPerson) {

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.