title: How to pass data from Controller to view in J2ee with spring
body: <p>I have a simple J2ee application with spring mvc. Now I want to call a method from the jsp page to his controller and I want to have an information from the controller. So I have write this code:</p>
  
  <p>registrazione.jsp:</p>
  
  <pre><code>&lt;script language="javascript"&gt;  
  
      function saveRigaTable2(){
  
          try{
              var nome = document.getElementById("nome").value;
              var ajaxHandler = new AjaxHandler('POST', '&lt;c:url value="${pageName}"/&gt;.html', false);   
              ajaxHandler.encodeParameter('method', 'saveItems');
              ajaxHandler.encodeParameter('nome', nome);
  
              ajaxHandler.callbackHandler = function()
              {           
                  if (ajaxHandler.getRequest().readyState == 4)
                  {   
                      if (ajaxHandler.getRequest().status == 200)
                      {
                          var xmlDoc = ajaxHandler.getRequest().responseXML;
  
                          var itemsException = xmlDoc.getElementsByTagName("exception");
                          alert(itemsException.length);
                          var items = xmlDoc.getElementsByTagName("registrazioneOK");
                          alert(items.length);
                          if (itemsException.length!=0)
                          {
                              var punto=itemsException[0];
                              alert(punto.getAttribute("text"));
                              document.getElementById("error").innerHTML=punto.getAttribute("text");
                              alert('Impossibile1 eseguire l\' operazione');
                          }
                          if (items.length!=0)
                          {
                              var punto=items[0];
                              alert(punto.getAttribute("text"));
                          }
                      }
                  }
              };
  
              ajaxHandler.startRequest();   
          }
          catch (e)
          {
              alert('Impossibile eseguire l\' operazione');
          }      
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>This is the method of Controller:</p>
  
  <pre><code>public ModelAndView saveItems(HttpServletRequest request, HttpServletResponse response) throws Exception
      {
          List dataSet = new ArrayList();
          Map dataItem = new HashMap();
          List attributes = new ArrayList();   
          Map model=new HashMap();
          try
          {
              String nome=request.getParameter("nome");
              User user = new User();
              user.setNome(nome);
              if(modelManager.getUserManager().saveUser(user)){
                  //request.getSession().setAttribute("rilasciataModificataConf", "SI");
                  //registrazione avvenuta con successo
                  dataItem.put("tagName", "registrazioneOK");
                  attributes.add(new Entity("text", "Complimenti. Registrazione avvenuta con successo." ));
                  dataItem.put("attributes", attributes);
                  dataSet.add(dataItem);  
                  model.put("dataSet", dataSet);
              }
  
  
          } catch (Exception e) {
              dataItem.put("tagName", "exception");
              attributes.add(new Entity("text", "Error in saving the current row" ));
              dataItem.put("attributes", attributes);
              dataSet.add(dataItem);  
              model.put("dataSet", dataSet);
              LoggerFactory.logStackTrace(e);
          }
          request.setAttribute("model", model);
          return new ModelAndView("secure/ajax_callback", model);
      }
  </code></pre>
  
  <p>This is the ajax_callback.jsp</p>
  
  <pre><code>&lt;%@ page contentType="text/xml"%&gt;
  &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt;
  &lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
  &lt;dataSet&gt;
     &lt;c:forEach var="dataItem" items="${dataSet}"&gt;
          &lt;&lt;c:out value="${dataItem.tagName}"/&gt; 
          &lt;c:forEach var="attribute" items="${dataItem.attributes}"&gt;
              &lt;c:out value="${attribute.id}"/&gt;="&lt;c:out value='${attribute.description}'/&gt;" 
          &lt;/c:forEach&gt;/&gt;
      &lt;/c:forEach&gt;
  &lt;/dataSet&gt;
  </code></pre>
  
  <p>When I run this code, I can't read the information, the lenght of the items is all time 0.
  Where is my error?</p>
  
  <p>EDIT: this is the reposnse of xml that I have from ajax_callback.jsp:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;dataSet&gt;
          &lt;
              exception 
  
                      text="Complimenti. Registrazione avvenuta con successo."        
          /&gt;
  </code></pre>
  
  <p>And this is the error of xml </p>
  
  <pre><code>Errore interpretazione XML: la dichiarazione XML o testuale non è all’inizio di un’entità Indirizzo: moz-nullprincipal:{d84efa50-0bb7-4f19-b93a-de7ebc15f366} Riga numero 3, colonna 1:
  
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  ^
  </code></pre>
  
  <p>I think the error is on the ajax_callback.jsp</p>