title: Unable to match csrf-token using ajax/json
body: <p>I have one login page, with a sign-in pop-up, which has username, password and a captcha. Each time when I try to post the form using ajax ( return value is json ), I will get an error like this:</p>
  
  <blockquote>
    <p>com.opensymphony.xwork2.ognl.OgnlValueStack  - Error setting expression <code>'struts.token.name'</code> with value <code>'[Ljava.lang.String;@53401791'</code> ognl.OgnlException: <strong>source is null for <code>getProperty(null, "token")</code></strong></p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>Form token B4KX7L4ER1FXK5BRJZJ19QTGG4EGRGME does not match the session token null</p>
  </blockquote>
  
  <p><strong>Login.jsp</strong></p>
  
  <pre class="lang-jsp prettyprint-override"><code>&lt;script&gt;
      var strutsToken = "&lt;s:property value="#session['struts.tokens.token']" /&gt;";
  &lt;/script&gt;
  </code></pre>
  
  <p>and inside body tag </p>
  
  <pre class="lang-jsp prettyprint-override"><code>&lt;s:token/&gt;
  </code></pre>
  
  <p><strong>Signin.jsp (Popup for login)</strong> </p>
  
  <pre class="lang-jsp prettyprint-override"><code>&lt;script&gt;
      var strutsToken = "&lt;s:property value="#session['struts.tokens.token']" /&gt;";
  &lt;/script&gt;
  
  &lt;script&gt;
  $(document).ready(function () {
  
      // For making new captcha image     
      var df = "Captcha?token=" + strutsToken + "&amp;struts.token.name=token";      
  
      $("#IMA").attr("src", df);   // IMA is id of captcha image    
  
      $('#mini').click(function () {   // mini is id of submit button
  
          $.post('Auth', {
              username: document.getElementById('username').value,
              pass: document.getElementById('pass').value,
              Captcha: document.getElementById('Captcha').value,
              token: strutsToken,
              'struts.token.name': "token"
          }, function (jsonResponse) {
              if (jsonResponse.res == "1") {   
                  console.log('valid');
                  window.location = "campaign/campaign_dashboard.jsp";
              }
              else if (jsonResponse.res == "2") {   
                  console.log('valid');
                  window.location = "Main.jsp";
              } else {
                  $('#result').text(jsonResponse.res);
              }
          }, 'json');
      });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>Struts.xml</strong></p>
  
  <pre class="lang-jsp prettyprint-override"><code> &lt;interceptor-stack name="myStack"&gt;
              &lt;interceptor-ref name="authenticationInterceptor" &gt;                                      &lt;/interceptor-ref&gt;              
              &lt;interceptor-ref name="cachingHeadersInterceptor" /&gt;
              &lt;interceptor-ref name="fileUpload" &gt;
              &lt;/interceptor-ref&gt;
              &lt;interceptor-ref name="token"&gt;&lt;/interceptor-ref&gt;
              &lt;interceptor-ref name="params"&gt;  
                  &lt;param name="params.excludeParams"&gt;
          token,dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*
      &lt;/param&gt;  
              &lt;/interceptor-ref&gt;  
              &lt;interceptor-ref name="defaultStack"/&gt;                                  
          &lt;/interceptor-stack&gt;
      &lt;/interceptors&gt;
      &lt;default-interceptor-ref name="myStack"/&gt;
  </code></pre>
  
  <p>What is preventing the token to be correctly passed to the action ?</p>