title: String response from servlet to javascript
body: <p>I have this code in java:</p>
  <pre><code>public static String Login (HttpServletRequest request) {
          
          if(Auth.AuthCheck(request.getParameter(&quot;user&quot;), request.getParameter(&quot;pass&quot;))) {
              HttpSession sesion = request.getSession();
              sesion.setAttribute(&quot;user&quot;, request.getParameter(&quot;user&quot;));
              
              return &quot;success&quot;;
              
          }else {
              return &quot;fail&quot;;
  
          }
  </code></pre>
  <p>&quot;AuthCheck&quot; is a method I created inside a class called &quot;Auth&quot;, It receives 2 string parameters (user and password from an html file), this is me trying to make a Login and the conde from above is a method ment to validate a user in the database, it works fine, the problem is that the string &quot;success&quot; or &quot;fail&quot; do return correctly apparently, and in the javascript side, it receives and shows in console the string correctly but when I try to use it in an &quot;if&quot; for some reason it won't work and it's driving me crazy. Heres the javascript code, where you can see the fetch api im using</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var myFormLogin = document.getElementById('form');
  var myButtonLogin = document.getElementById('IdBotonLogin');
  
  
  const sendLogin = (e)=&gt;{
   e.preventDefault();
  
  const formData = new FormData(myFormLogin);
  
  
  fetch('http://localhost:8080/prim/Login', {
      method: 'post',
      body: formData        
  }).then((Response)=&gt;{
      return Response.text();
  }).then((text)=&gt;{
      
      console.log(text); 
      
      if(text == "success"){
          location.href = 'redirect.html';
      }
      
  }).catch((error)=&gt;{
      console.error(error);
  })
  
  };
  myButtonLogin.onclick = sendLogin;</code></pre>
  </div>
  </div>
  </p>
  <p>As you can see, in the &quot;if&quot; above(javascript code) I'm comparing the String recieved from the servlet side with the string &quot;success&quot; and it's supposed to be &quot;true&quot; but it says &quot;false&quot; when I put the line console.log(text == &quot;success&quot;); down console.log(text);, another thing that is very interesting is that if I put this text+='pppp'; it prints the following:</p>
  <pre><code>success
  pppp
  </code></pre>
  <p>They are aparted, not in the same line, next to each other... for the rest of the code it &quot;works&quot;, it's just this thing.</p>