I have index.jsp. This jsp calls the controller:
@Controller
public class CustomerController {
//Other code..
//..
String customerJSON = null;
ModelAndView model = new ModelAndView("index", "customerJSON", customerJSON);
return model;
}
customerJSON is a string that contains JSON information.
Controller returns customerJSON to jsp.
Now, in jsp, I want to show customerJSON into an alert.
In jsp I add:
<script>
var customer = "<c:out value='${customerJSON}'/>";
alert(customer);
</script>
The problem is that, this alert, starts when the page is loaded and not when the controller returns to jsp.
How can I show the alert after controller call and not when the page is loaded?
I would implement your controller method (and requestmapping) something like this:
If you have jackson as dependency that will take care of json-serializing for you.
Then your javascript (using jquery) code could look something like this: