I have been struggling to implement the following scenario using Spring MVC. I am encountering issues and unable to determine the correct approach. My implementation involves jsonRequest/jsonResponse (Restful Web services).
1. I have a SignUP.jsp Form with multiple fields that need to be submitted to the controller.
<form method="POST" onsubmit="javascript:signupObj.signup()">
<table>
<tr>
<td>Username :</td>
<td><input id="username"/></td>
</tr>
<tr>
<td>Password :</td>
<td><input id="password"/></td>
</tr>
<tr>
<td>
<button type="submit">Submit</button>
</td>
</tr>
</table>
</form>
2. Upon submission of the form, it will invoke the signup Javascript function as mentioned below:
var signupObj = {
showSignup: function() {
$.ajax({
type: "GET",
url: "showSignup",
success: function(response) {
$("#signupView").html( response );
}
});
},
signup: function() {
// Signup function code
}
redirectview: function(message,data) {
// Redirect view function code
}
};
3. The above JavaScript function makes an ajax call to the controller using jsonResponse as input.
// Controller methods for signup and success views
4. The Controller response returns a JSON object. Based on the profileDTO.getErrors, loginSuccess.jsp or loginFailure.jsp needs to be called.
My Questions are:
1) How can I use jsonResponse in ajax calls to redirect to loginSuccess.jsp or loginFailure.jsp and pass my profileDTO data to the loginSuccess view?
2.) Please suggest the best practices to be followed in this scenario.