title: How to pass a string variable from servlet to jsp and store the value in another variable?
body: <p>I want to pass a string variable from servlet to jsp and store it's value in another variable in jsp.</p>
  
  <p>Here is servlet:</p>
  
  <pre><code>request.setAttribute("rep", docbase);
  request.getRequestDispatcher("Welcome.jsp").forward(request, response);
  </code></pre>
  
  <p>Here is my jsp:</p>
  
  <pre><code>&lt;/script&gt;
          &lt;script type="text/ajavscript"&gt;
          var repository = '${rep}';
  
          &lt;/script&gt;
           &lt;script type="text/javascript"&gt;
          $(document).ready(function() {        
            alert('.repository');
              $.ajax({
               url:'ServiceToFetchDocType',
               data: {name:repository},
               type:'post',
               cache:false,
               success: function(response)
               {
  
  
               }
              });
  
          });
  
  
          &lt;/script&gt;
  </code></pre>
  
  <p>The alert box is showing undefined. I'm not sure if I'm able to pass the value successfully.</p>