title: How to display same city name in all JSP pages in Spring Boot?
body: <p>I am working on an ecommerce web application in Spring Boot. I have city name that needs to be displayed in all JSP pages. For example, If I choose city name as Mumbai, then whatever be the number of JSP pages is there (excluding checkout page) same city name should be displayed (i.e. Mumbai should be displayed in all pages except checkout page). So, I tried to get this thing done with the use of query parameter. But unable to display same city name in another pages ( if I click on some other links to redirect to another page).</p>
  <p>From below script, I get city name from query parameter from index.jsp and displayed it in webheader.jsp.</p>
  <pre><code>    function getcities(){
                  var city = document.getElementById('cityname').value;
                  var url = &quot;api/getcities&quot;;
                  $.post(url, {
                      city : city,
                  }, function(data, status) {
                      if (data.status == &quot;OK&quot;) {
                          if (data.statusCode == 1) {
                              var citylist = data.response;
                              var citylistlen = citylist.length;
                              var city = &quot;&quot;; 
                              if(citylistlen &gt; 0){
                                  for(var i = 0; i &lt; citylistlen; i++){
                                      var pincode = citylist[i].pincode;
                                      var cityname = citylist[i].delivercityid.city;
                                      if(null != pincode &amp;&amp; null != cityname){
                                          city = city + &quot;&lt;div style='border: 1px solid; padding: 5px; display: block; z-index: 100;  position: inherit; font-style: oblique; color: blueviolet;' onclick=\&quot;getcitydata('&quot;+citylist[i].delivercityid.delivercityid+&quot;','&quot;+cityname+&quot;')\&quot;&gt;&quot;
                                          +&quot;&lt;div&gt;&lt;div style='padding: 5px;'&gt;&lt;a href=\&quot;..&lt;%=WebUrl.index%&gt;?city=&quot;+cityname+&quot;\&quot;&gt;&lt;strong style=\&quot;color: indigo;\&quot;&gt;&quot;+cityname+&quot;&lt;/strong&gt;&amp;nbsp;(&quot;+pincode+&quot;)&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&quot;;
                                      }
                                  }
                              }
                              document.getElementById('showcity').innerHTML = city;
                          } else {
                              var error = data.responseMessage;
                              swal(error, &quot;&quot;, &quot;error&quot;);
                          }
                      } else {
                          var error = data.responseMessage;
                          swal(error, &quot;&quot;, &quot;error&quot;);
                      }
                  });
              } 
  </code></pre>
  <p>Inside webheader.jsp:</p>
  <pre><code>    &lt;div class=&quot;city-popup&quot;&gt;
              &lt;div id=&quot;user-selected-city-input&quot;&gt;
                  &lt;h6&gt;Delivery In&lt;/h6&gt;
                      &lt;%
                          String cityname = request.getParameter(&quot;city&quot;); 
                          if(cityname == null){
                           out.print(&quot;&lt;h6 style=\&quot;color: #330000;\&quot;&gt;Choose City&lt;/h6&gt;&quot;);
                          }else{
                           out.print(&quot;&lt;h5 style=\&quot;color: #330000;\&quot;&gt;&quot;+cityname+&quot;&lt;/h5&gt;&quot;);
                          }
                      %&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  </code></pre>
  <p>What and how should it done? Do I need to use cookies or something else to do so?</p>
  <p><a href="https://i.stack.imgur.com/cFhle.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cFhle.jpg" alt="Picked some city name" /></a></p>
  <p><a href="https://i.stack.imgur.com/vQOqL.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vQOqL.jpg" alt="Screenshot to show other JSP page" /></a></p>