1

I'm current using Spring MVC and Hibernate to add user into my Database, MySQL. When I click on Register button I will get a HTTP Status 400 - The request sent by the client was syntactically incorrect.

registerform.jsp

    <form:form commandName="form" action="${pageContext.request.contextPath}/register.jsp" method="POST">
                <div class="ribbon">
                    <h3>Login Information</h3>
                    <br />
                    <table align="center">
                        <tr>
                            <td><label id="userEmail">Email Address:</label></td>
                            <td><form:input path="userEmail" /></td>
                        </tr>
                        <tr>
                            <td><label id="userPassword">Password:</label></td>
                            <td><form:input path="userPassword" /></td>
                        </tr>
                    </table>
                </div>

                <div class="ribbon">
                    <h3>Personal Information</h3>
                    <br />
                    <table align="center">
                        <tr>
                            <td><label id="userName">Full Name:</label></td>
                            <td><form:input path="userName" /></td>
                        </tr>
                        <tr>
                            <td><label id="userGender">Gender:</label></td>
                            <td><form:input path="userGender" /></td>
                        </tr>
                        <tr>
                            <td><label id="userDOB">Date of Birth:</label></td>
                            <td><form:input path="userDOB" /></td>
                        </tr>
                        <tr>
                            <td><label id="userContact">Contact:</label></td>
                            <td><form:input path="userContact" /></td>
                        </tr>
                    </table>
                </div>

                <div class="ribbon">
                    <h3>Address Information</h3>
                    <br />
                    <table align="center">
                        <tr>
                            <td><label id="userAddress">Address:</label></td>
                            <td><form:input path="userAddress" /></td>
                        </tr>
                        <tr>
                            <td colspan="2"><input type="submit" value="Register" />
                                <button type="button" name="back"
                                    onclick="window.location='index.jsp'">back</button></td>
                        </tr>
                    </table>
                </div>
</form:form>

UserController.java

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/register")
    public ModelAndView addUser() {

        // direct to registerform page
        ModelAndView model = new ModelAndView("registerform");

        // add form as a new userTO
        model.addObject("form", new UserTO());
        return model;
    }

    @RequestMapping(value = "/register", method = RequestMethod.POST)
    public ModelAndView addUser(@ModelAttribute UserTO userTO) {

        ModelAndView model = new ModelAndView("registerform");
        userService.registerUser(userTO);

        String message = "User registration successful!";
        model.addObject("message", message);
        return model;

    }

}

UserTO.java

    @Entity
@Table(name = "tbl_user")
public class UserTO implements Serializable {

    private static final long serialVersionUID = -4082995725312571363L;

    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    @Column(name = "USER_ID")
    private String userId;

    @Column(name = "USER_EMAIL")
    private String userEmail;

    @Column(name = "USER_PASSWORD")
    private String userPassword;

    @Column(name = "USER_NAME")
    private String userName;

    @Column(name = "USER_GENDER")
    private String userGender;

    @Column(name = "USER_DOB")
    private Date userDOB;

    @Column(name = "USER_CONTACT")
    private String userContact;

    @Column(name = "USER_ADDRESS")
    private String userAddress;

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserEmail() {
        return userEmail;
    }

    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }

    public String getUserPassword() {
        return userPassword;
    }

    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserGender() {
        return userGender;
    }

    public void setUserGender(String userGender) {
        this.userGender = userGender;
    }

    public Date getUserDOB() {
        return userDOB;
    }

    public void setUserDOB(Date userDOB) {
        this.userDOB = userDOB;
    }

    public String getUserContact() {
        return userContact;
    }

    public void setUserContact(String userContact) {
        this.userContact = userContact;
    }

    public String getUserAddress() {
        return userAddress;
    }

    public void setUserAddress(String userAddress) {
        this.userAddress = userAddress;
    }

}   
Khee
  • 39
  • 1
  • 7

0 Answers0