The following JavaScript
new Ajax.Request('/orders/check_first_last/A15Z2W2',
{asynchronous:true, evalScripts:true,
parameters:{first:$('input_initial').value,
last:$('input_final').value,
order_quantity:$('input_quantity').value}});
triggers an Ajax call to the checkFirstLast
method in the OrderController
:
@Controller
@RequestMapping("/orders")
public OrderController {
@RequestMapping("/check_first_last/{code}")
@ResponseBody
public String checkFirstLast(@PathVariable String code,
@RequestParam int first,
@RequestParam int last,
@RequestParam("order_quantity") int orderQuantity) {
Integer newResult = new Integer(last - first);
return newResult.toString();
}
}
If I want to write the newResult
String from the checkFirstLast
method into the result_text
HTML element on the page that sends the Ajax request, replacing the value set by the initialResult
JSTL variable:
<h2 id="result_text"><c:out value="${initialResult}"/></h2>
what change would I need to make to the controller method above (checkFirstLast
), now that I have already included the Jackson JSON library in my project?