Quickstart - GET request with Controller interface

With the Controller interface validating or binding is not supported by Spring. It is easy to use it for GET requests.

The Json view response is just the Json string of the Model-Map created in the Controller. No errors are included or values formated.

The following code from the [ Demo application] shows all the code used to create a simple Json GET controller

Spring ApplicationContext

    <bean name="simpleJsonGetController" 
    <bean name="urlMapping" 
        <property name="mappings">
                <prop key="/hello.json">simpleJsonGetController</prop>
    <bean name="viewResolver" 
        class="org.springframework.web.servlet.view.XmlViewResolver" />

Spring view.xml

    <bean name="jsonView" class="org.springframework.web.servlet.view.json.JsonView"/>


                First Test Spring Json Demo
        <script type="text/javascript" src="script/prototype.js"></script>
        <script type="text/javascript" src="script/behaviour.js"></script>
        <script type="text/javascript" src="script/behaviour-roles.js"></script>
        <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"/>
        <h1>Spring JSON DEMO</h1>
        <h2>Spring Ajax Get (ControlerInterface)</h2>
        <b>firstname : </b><span id="firstname"></span><br/>
        <b>secondname : </b><span id="secondname"></span><br/>
        <button id="getName">get name</button>
        <button id="clearName">clear name</button><br/>

JavaScript behaviour-roles.js

var printResult = function(transport){
                var result = 
                        "Status : " + transport.status
                        + "\n"
                        + "\n"
                        + "Json-Result:"
                        + "\n" + transport.responseText;
var myrules = {
        'button#getName' : function(element){
                element.onclick = function(){
                        new Ajax.Request('hello.json', { method:'get',
                                onSuccess: function(transport, json){
                                        var json = transport.responseText.evalJSON();
                                        $('firstname').innerHTML = json.firstname;
                                        $('secondname').innerHTML = json.secondname;
        'button#clearName' : function(element){
                element.onclick = function(){
                        $('firstname').innerHTML = '';
                        $('secondname').innerHTML = '';


Controller Source

public class SimpleJsonGetController implements Controller {

        public ModelAndView handleRequest(HttpServletRequest request,
                        HttpServletResponse response) throws ServletException, IOException {

                Map model = new HashMap();
                model.put("firstname", "Peter");
                model.put("secondname", "Schmitt");

                return new ModelAndView("jsonView", model);


 Status : 200