title: How to pass JSP variables to servlet?
body: <p>I am trying to pass two values from my JSP page to servlet using request dispatcher.</p>
  
  <p>Here is the JSP code:</p>
  
  <pre><code>&lt;%
              String companyName = (String) request
                      .getAttribute("adminCompnayName");
              String tenantId = (String) request.getAttribute("adminTenantId");
  
              request.setAttribute("adminCompnayName", companyName);
  
              request.setAttribute("adminTenantId", tenantId);
  
  request.setAttribute("adminTenantid","my compnay");
              request.setAttribute("adminCompanyname"," my tenant id");
              String servletName="../StoreUserDetails";
              RequestDispatcher dispatcher = request.getRequestDispatcher(servletName);
              if (dispatcher != null){
              dispatcher.forward(request, response);
              } 
  </code></pre>
  
  <p>These two values are received from another servlet.</p>
  
  <p>Here is the servlet code where I am receiving values.</p>
  
  <pre><code>String tenantId = (String) request.getAttribute("adminTenantid");
          String companyName = (String) request
                  .getAttribute("adminCompanyname");
  
  
  
  
  out.println("--------------------------"
                  + request.getAttribute("adminTenantid"));
          out.println("--------------------------"
                  + request.getAttribute("adminCompanyname"));
  </code></pre>
  
  <p>But I am getting null values.</p>
  
  <pre><code>--------------------------null 
  
  --------------------------null
  </code></pre>
  
  <p>How to fix it?</p>