title: Spring MVC : Tying session attributes to each browser tab
body: <ul>
  <li>I am working on Spring-MVC application in which I am setting and
  getting some session attributes which I need in backend. The problem
  is, Spring or the browser, someone out of the both is tying these
  session attributes to different browsers rather than different tabs.
  <ul>
  <li>So if I open a new tab in the same browser, then it is updating the
  session attribute for both tabs.
  How can I remedy this problem? I tried using session to scope, request, etc. But nothing works. here is my controller and servlet-context.xml</li>
  </ul></li>
  </ul>
  
  <p>Controller :</p>
  
  <pre><code>@Controller
  @Scope("request")
  public class PersonController {
  
  
      @Secured("ROLE_USER")
      @RequestMapping(value = "/loadsection/{id}")
      public String loadNotePage(@PathVariable("id") Integer id, HttpSession session) {
  // here i am setting the canvasid, which I would like to access in other methods
          session.setAttribute("canvasid",id);
          if (this.personService.returnCurrentOperationalMode()) {
  
              session.setAttribute("canvasid",id);
              return "redirect:/section/listing";
          } else {
              GroupCanvas mcanvas = this.groupCanvasService.getCanvasById(id);
              this.personService.setCurrentCanvas(mcanvas.getMcanvasid());
  
              return "redirect:/section/listing";
          }
  
      }
  
  
      @Secured("ROLE_USER")
      @RequestMapping(value = "/addbatchsections", method = RequestMethod.POST)
      public @ResponseBody String addBatchSections(HttpSession session, @RequestBody Section[] sections) {
          int canvasid = (Integer) session.getAttribute("canvasid");
          try {
              List&lt;Section&gt; sectionList = new ArrayList&lt;&gt;();
              for (Section section : sections) {
                  sectionList.add(section);
              }
              this.sectionService.addBatchSections(sectionList,canvasid);
              return "success";
          } catch (Exception e) {
              return "failure";
          }
      }
  </code></pre>
  
  <p>Servlet-Context.xml</p>
  
  <pre><code>   &lt;mvc:annotation-driven/&gt;
  
      &lt;mvc:default-servlet-handler/&gt;
  
      &lt;resources mapping="/resources/" location="/resources/" /&gt;
  
      &lt;beans:bean
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;beans:property name="prefix" value="/WEB-INF/views/" /&gt;
          &lt;beans:property name="suffix" value=".jsp" /&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
          destroy-method="close"&gt;
          &lt;beans:property name="driverClassName" value="org.postgresql.Driver"  /&gt;
          &lt;beans:property name="url"
              value="jdbc:postgresql://localhost:5432/Person2"/&gt;
          &lt;beans:property name="username" value="postgres" /&gt;
          &lt;beans:property name="password" value="asayhk2787" /&gt;
          &lt;beans:property name="removeAbandoned" value="true"/&gt;
          &lt;beans:property name="removeAbandonedTimeout" value="20"/&gt;
          &lt;beans:property name="defaultAutoCommit" value="false"/&gt;
      &lt;/beans:bean&gt;
  
  
      &lt;!-- Hibernate 4 SessionFactory Bean definition --&gt;
      &lt;beans:bean id="hibernate4AnnotatedSessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;beans:property name="dataSource" ref="dataSource"  /&gt;
          &lt;beans:property name="annotatedClasses"&gt;
              &lt;beans:list&gt;
                  &lt;beans:value&gt;com.journaldev.spring.model.Person&lt;/beans:value&gt;
                  &lt;beans:value&gt;com.journaldev.spring.model.Notes&lt;/beans:value&gt;
                  &lt;beans:value&gt;com.journaldev.spring.model.Canvas&lt;/beans:value&gt;
                  &lt;beans:value&gt;com.journaldev.spring.model.Section&lt;/beans:value&gt;
                  &lt;beans:value&gt;com.journaldev.spring.model.Attachment&lt;/beans:value&gt;
  
                  &lt;beans:value&gt;com.journaldev.spring.model.GroupAccount&lt;/beans:value&gt;
                  &lt;beans:value&gt;com.journaldev.spring.model.GroupMembers&lt;/beans:value&gt;
                  &lt;beans:value&gt;com.journaldev.spring.model.GroupCanvas&lt;/beans:value&gt;
                  &lt;beans:value&gt;com.journaldev.spring.model.GroupSection&lt;/beans:value&gt;
                  &lt;beans:value&gt;com.journaldev.spring.model.GroupNotes&lt;/beans:value&gt;
                  &lt;beans:value&gt;com.journaldev.spring.model.GroupAttachments&lt;/beans:value&gt;
  
                  &lt;beans:value&gt;com.journaldev.spring.model.Token&lt;/beans:value&gt;
                  &lt;beans:value&gt;com.journaldev.spring.model.WaitingMembers&lt;/beans:value&gt;
                  &lt;beans:value&gt;com.journaldev.spring.model.NoteHistory&lt;/beans:value&gt;
                  &lt;beans:value&gt;com.journaldev.spring.model.GroupNoteHistory&lt;/beans:value&gt;
  
                  &lt;beans:value&gt;com.journaldev.spring.model.Feedback&lt;/beans:value&gt;
              &lt;/beans:list&gt;
          &lt;/beans:property&gt;
          &lt;beans:property name="hibernateProperties"&gt;
              &lt;beans:props&gt;
                  &lt;beans:prop key="hibernate.dialect"&gt;org.hibernate.dialect.PostgreSQL82Dialect
                  &lt;/beans:prop&gt;
                  &lt;beans:prop key="hibernate.show_sql"&gt;false&lt;/beans:prop&gt;
                  &lt;beans:prop key="connection.pool_size"&gt;200&lt;/beans:prop&gt;
                  &lt;beans:prop key="c3p0.max_size"&gt;200&lt;/beans:prop&gt;
                  &lt;beans:prop key="c3p0.timeout"&gt;1000&lt;/beans:prop&gt;
                  &lt;beans:prop key="hibernate.jdbc.batch_size"&gt;100&lt;/beans:prop&gt;
                  &lt;beans:prop key="hibernate.order_updates"&gt;true&lt;/beans:prop&gt;
  
              &lt;/beans:props&gt;
          &lt;/beans:property&gt;
      &lt;/beans:bean&gt;
  
      &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  
      &lt;beans:bean id="transactionManager"
                  class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory"/&gt;
      &lt;/beans:bean&gt;
  </code></pre>
  
  <p>I hope my question was clear, if there is any doubt, please feel free to ask me. Thanks a lot. :-)</p>